hdu 1085 母函数
题意:给出1分 2分 5分硬币的个数,问最小的不能组合出的值是多少。
const int M = 8005; int a[2][M], p, q, sum; int c[4], m[4]={0, 1, 2, 5}; int main(){ #ifndef ONLINE_JUDGE //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); #endif while(scanf("%d%d%d", &c[1], &c[2], &c[3]), c[1]|c[2]|c[3]){ sum = p = 0; a[0][0] = 1; memset(a[1], 0, sizeof a[1]); FOE(i, 1, 3){ q = 1 - p; sum += m[i] * c[i]; FOE(j, 0, sum) if(a[p][j]) for(int k=0; k<=c[i] && j+k*m[i]<=sum; k++) a[q][j+k*m[i]] += a[p][j]; memset(a[p], 0, sizeof a[p]); p = q; } FOR(i, 0, sum+2) if(a[q][i]==0) {printf("%d\n", i); break;} } return 0; }