记录编号 |
126651 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[NOIP 2010冲刺三]宁采臣的书架 |
最终得分 |
100 |
用户昵称 |
Ezio |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
3.482 s |
提交时间 |
2014-10-13 21:01:14 |
内存使用 |
2.70 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <queue>
#include <map>
#include <vector>
#define scafn scanf
#define For(st,ed,i) for(int i=st;i<=ed;++i)
#define Fordown(st,ed,i) for(int i=st;i>=ed;--i)
#define start(a,flag) memset(a,flag,sizeof(a));
using namespace std;
typedef long long ll;typedef unsigned int uint;typedef unsigned long long ull;
const int INF=0x7f7f7f7f;
int b[111],d[2][111][1<<8][11],o[1<<8];
int main()
{
freopen("arrangement.in","r",stdin);
freopen("arrangement.out","w",stdout);
For(0,(1<<8)-1,i){
o[i]=0;
For(0,7,j)if(i&(1<<j))o[i]++;
}
int t=0,n,k;
while(scanf("%d%d",&n,&k)!=EOF&&(n+k)){
int S=0,h=0;
For(1,n,i){
scanf("%d",&b[i]);
b[i]-=25;
S=S|(1<<b[i]);
h=max(h,b[i]);
}++h;start(d[0],0x7f);
d[0][0][(1<<b[1])][b[1]]=1;
d[0][1][0][h]=0;
int c=0,p=0;
For(1,n-1,i){
c=p^1;
start(d[c],0x7f);
For(0,k,j)For(0,S,s)For(0,h,l){
if(d[p][j][s][l]==INF) continue;
d[c][j][s|(1<<b[i+1])][b[i+1]]=min(d[c][j][s|(1<<b[i+1])][b[i+1]],d[p][j][s][l]+(b[i+1]==l?0:1));
d[c][j+1][s][l]=min(d[c][j][s][l],d[p][j][s][l]);
}p=c;
}int ans=INF;
For(0,k,j)For(0,S,s)For(0,h-1,l){
if(d[c][j][s][l]==INF)continue;
int t=S^s;
ans=min(ans,d[c][j][s][l]+o[t]);
}printf("Case %d: %d\n\n",++t,ans);
}
return 0;
}