HDU's ACM 2110 Crisis of HDU
2014-11-17 23:34
375 查看
原题链接:HDU's ACM 2110 Crisis of HDU
分析:又一道母函数题目,可参考HDU's ACM 1028 Ignatius and the Princess III,思路类似,不同之处在于系数与指数由pi,mi指定。
AC Code:
分析:又一道母函数题目,可参考HDU's ACM 1028 Ignatius and the Princess III,思路类似,不同之处在于系数与指数由pi,mi指定。
AC Code:
<span style="font-family:Microsoft YaHei;font-size:14px;">#include <stdio.h> #include <string.h> #define MAXN 10000 #define NUM_MAX 105 int coeff1[MAXN]; int coeff2[MAXN]; int p[NUM_MAX]; int m[NUM_MAX]; int main() { int n; int i, j, k, end; int sum, target; while(scanf("%d", &n) == 1 && n) { sum = 0; for(i=0;i<n;++i) { scanf("%d%d", &p[i], &m[i]); sum += p[i]*m[i]; } if(sum%3){ printf("sorry\n"); continue; } target = sum/3; memset(coeff1, 0, sizeof(coeff1)); memset(coeff2, 0, sizeof(coeff2)); end = p[0]*m[0]; for(i=0;i<=end && i<=target;i+=p[0]) coeff1[i] = 1; for(i=1;i<n;++i){ end = p[i]*m[i]; for(j=0;j<=target;++j) for(k=0;k<=end;k+=p[i]){ if(j+k>target) break; coeff2[j+k] += coeff1[j]; } for(j=0;j<=target;++j){ coeff1[j] = coeff2[j]%10000; coeff2[j] = 0; } } if(coeff1[target]) printf("%d\n", coeff1[target]); else printf("sorry\n"); } return 0; }</span>
相关文章推荐
- 杭电2110-Crisis of HDU
- 杭电ACM hdu 2110 Crisis of HDU 解题报告(母函数)
- hdu 2110 Crisis of HDU
- hdu_2110_Crisis of HDU(母函数)
- HDU 2110 Crisis of HDU
- HDU 2110 Crisis of HDU
- HDOJ-2110 Crisis of HDU(母函数)
- hdu 2110 Crisis of HDU(母函数)
- HDU 2110-Crisis of HDU(母函数)
- HDU 2110 Crisis of HDU (母函数问题)
- hdu 2110 Crisis of HDU(母函数)
- hdu 2110 Crisis of HDU(母函数)
- hdu_2110_Crisis of HDU(母函数)
- hdu 2110 Crisis of HDU (完全背包求方案总数)
- HDU-2110 Crisis of HDU
- Combinatorics——HDUOJ 2110 - Crisis of HDU(母函数 / 多重背包思想)
- HDU 2110 Crisis of HDU 【母函数】
- HDU 2110——Crisis of HDU
- 母函数系列之Crisis of HDU hdoj 2110
- hdu 2110 Crisis of HDU