HDU1709 天平
来源:互联网 发布:mac 股票行情软件 编辑:程序博客网 时间:2024/04/29 02:57
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1709
给你一些砝码的质量,求出1到总质量中不能表达的质量的个数和具体的值。
思路:和普通的母函数不一样的地方就是砝码可以放在重物那一边,所以多了个c2[abs(j-k)]+=c1[j];
#include<iostream>#include<math.h>#include<string.h>using namespace std;#define maxn 10110int c1[maxn], c2[maxn];int main(){ int T, i, j; int a[200],maxsum=0; while (cin >> T) { maxsum = 0; memset(a, 0, sizeof(a)); memset(c1, 0, sizeof(c1)); memset(c2, 0, sizeof(c2)); for (i = 1; i <= T; i++) { cin >> a[i]; maxsum += a[i]; } c1[a[1]] = 1; c1[0] = 1; int m = a[1];//表示当前的最高项 for (i = 2; i <= T; i++) { for (j = 0; j <= m; j++) for (int k = 0; k <= a[i]; k += a[i]) { c2[j + k] += c1[j]; c2[abs(j - k)] += c1[j]; } m += a[i]; for (j = 0; j <= m; j++) { c1[j] = c2[j]; c2[j] = 0; } } int ans = 0,q[maxn]; for (i = 0; i <= maxsum; i++) { if (c1[i] == 0) q[ans++] = i; } cout << ans << endl; if (ans != 0) { int mm; for ( mm = 0; mm < ans - 1; mm++) { cout << q[mm] << " "; } cout << q[mm]<<endl; } } return 0;}
阅读全文
0 0
- HDU1709 天平
- hdu1709
- HDU1709
- hdu1709
- 天平
- HDU1709 DP
- hdu1709 the blance
- HDU1709-----简单的DP
- hdu1709 The Balance
- hdu1709(母函数)
- HDU1709(母函数)
- HDU1709母函数
- hdu1709 The Balance
- HDU1709 The Balance 【母函数】
- HDU1709 The Balance【母函数】
- 天平感悟
- 天平问题
- 天平称重
- 高德地图的坑
- jmeter源码---gui简单介绍
- 用dom4j解析xml,soap报文
- Qt中的文件操作
- iOS内置购买之提交指南-协议、税务和银行业务
- HDU1709 天平
- angular select ng-options和ng-repeat
- HBase shell scan 模糊查询
- 笔记—自定义View之属性动画进阶篇
- 适合少儿学习编程的工具
- 抽象
- 《Java编程思想》自限定
- linux tomcat 配置远程调试
- ubuntu 16.04 14.04 安装各种软件