Holding Bin-Laden Captive! - http://acm.hdu.edu.cn/showproblem.php?pid=1085
代码
【31MS】
#include<bits/stdc++.h>
using namespace std;
#define MXN 8010
int main(){
int N, c1[MXN], c2[MXN], c[3]={1,2,5}, nc[3];
while(scanf("%d%d%d", nc, nc+1, nc+2)){
if(nc[0] == 0 && nc[1] == 0 && nc[2] == 0) break;
memset(c1, 0, sizeof c1);
memset(c2, 0, sizeof c2);
for(int i = 0; i <= nc[0]; i++) c1[i] = 1;
N = nc[0];
for(int i = 1; i <= 2; i++){
for(int j = 0; j <= N; j++){
for(int k = 0; k <= c[i]*nc[i]; k += c[i]){
c2[j+k] += c1[j];
}
}
N += nc[i]*c[i]; // 注意与后一句的顺序
for(int j = 0; j <= N; j++) c1[j] = c2[j], c2[j] = 0;
}
for(int i = 0; i <= N+1; i++){
if(c1[i] == 0){
printf("%d\n", i);
break;
}
}
}
return 0;
}