比赛 |
20111108 |
评测结果 |
AAAAAAAAAA |
题目名称 |
机房 |
最终得分 |
100 |
用户昵称 |
fanzeyi |
运行时间 |
0.000 s |
代码语言 |
C |
内存使用 |
0.00 MiB |
提交时间 |
2011-11-08 11:05:18 |
显示代码纯文本
/*
ID: fanzeyi1
LANG: C
TASK: orz
*/
/*
* =====================================================================================
*
* Filename: orz.c
* Version: 1.0
* Created: 11/08/2011 10:31:29 AM
* Revision: none
* Compiler: gcc
* Author: Zeray Fan, fanzeyi1994[at]gmail.com
* Company: http://www.fanhe.org/
*
* =====================================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int num[2502];
int f[2502];
inline int min(int a, int b){
return a < b ? a : b;
}
int main(void) {
FILE *fin = fopen("orz.in","r");
FILE *fout = fopen("orz.out", "w");
int i, j;
int n, m;
int cow1, cow2;
memset(num, 0, sizeof(num));
memset(f, 0x7F, sizeof(f));
f[0] = 0;
fscanf(fin, "%d %d", &n, &m);
for( i = 1 ; i <= n ; i++ ) {
fscanf(fin, "%d", &num[i]);
}
for( i = 1 ; i <= n ; i++ ) {
cow1 = 0;
cow2 = 0;
if(num[i]&1) {
cow1 = 1;
}else{
cow2 = 1;
}
for( j = i - 1 ; j >= 0 ; j-- ) {
if(!(abs(cow1 - cow2) > m && !(cow1 == 0 || cow2 == 0))) {
f[i] = min(f[i], f[j]+1);
}
if(num[j]&1) {
cow1 = cow1 + 1;
}else{
cow2 = cow2 + 1;
}
}
}
fprintf(fout, "%d\n", f[n]);
return 0;
}