1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #define MAX 10010
  5. int c1[MAX], c2[MAX], num[110];
  6. /* 题目大意: 给你n种砝码,从1到n中砝码的重量和其中不能称出多少种重量,输出不能称出的总数和类别*/
  7. int main()
  8. {
  9. int n;
  10. while( scanf("%d", &n)!=EOF )
  11. {
  12. memset(num, 0, sizeof(num) );
  13. memset(c1, 0, sizeof(c1) );
  14. memset(c2, 0, sizeof(c2) );
  15. int total = 0;
  16. for(int i=0; i<n; i++) //重量输入
  17. {scanf("%d", &num[i]); total+=num[i];}
  18. //for(int i=0; i<=total; i++)
  19. //c1[i] = c2[i] = 0;
  20. c1[0] = 1; //第一个括号,重量为0的
  21. for(int i=0; i<n; i++)
  22. {
  23. for(int j=0; j<=total; j++)
  24. {
  25. c2[j] |= c1[j]; //否能称得,自己砝码的重量
  26. if(num[i] + j <=total) //重量和是否大于总重量
  27. c2[j+num[i]] |= c1[j]; //重量和
  28. c2[abs(j-num[i])] |= c1[j]; //重量差
  29. }
  30. for(int j=0; j<=total; j++) //一次循环赋值
  31. {c1[j] = c2[j]; c2[j] = 0;}
  32. }
  33. int count = 0;
  34. for(int i=0; i<=total; i++) //查找能否称得的重量
  35. {
  36. if(!c1[i])
  37. c2[count++] = i;
  38. }
  39. printf("%d\n", count);
  40. for(int i=0; i<count-1; i++)
  41. printf("%d ", c2[i]);
  42. if(count) printf("%d\n", c2[count-1]);
  43. }
  44. return 0;
  45. }
  46. /*
  47. Problem Description
  48. Now you are asked to measure a dose of medicine with a balance and a number of weights. Certainly it is not always achievable. So you should find out the qualities which cannot be measured from the range [1,S]. S is the total quality of all the weights.
  49. Input
  50. The input consists of multiple test cases, and each case begins with a single positive integer N (1<=N<=100) on a line by itself indicating the number of weights you have. Followed by N integers Ai (1<=i<=N), indicating the quality of each weight where 1<=Ai<=100.
  51. Output
  52. For each input set, you should first print a line specifying the number of qualities which cannot be measured. Then print another line which consists all the irrealizable qualities if the number is not zero.
  53. Sample Input
  54. 3
  55. 1 2 4
  56. 3
  57. 9 2 1
  58. Sample Output
  59. 0
  60. 2
  61. 4 5
  62. */
来自为知笔记(Wiz)

附件列表

转载于:https://www.cnblogs.com/sober-reflection/p/030bcb6e395767a11e6c170a46e258f7.html

hdu 1709 母函数变形相关推荐

  1. hdu 1709 (母函数,有些特殊)

    点击打开链接 母函数.. #include"stdio.h" #include"string.h" int main() {int a[10008];int b ...

  2. HDOJ HDU 1709 The Balance ACM 1709 IN HDU

    //MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址 :          http://acm.hdu.edu.cn/showproblem.php?pid=1 ...

  3. HDU2110 Crisis of HDU【母函数】

    Crisis of HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. hdu 5087(LIS变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5087 解题思路:这道题其实仔细想想很简单,次长LIS只有两种可能,一种就是等于LIS-1,一种就是LI ...

  5. hdu 5410(背包问题变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5410 解题思路:令dp[i][j][0]表示前i种物品,共j钱,不买第i种物品所能买到的最大值.dp[ ...

  6. hdu 1598(最小生成树变形)

    解题思路:这道题我一开始的思路是动规,dp_max[i][j]表示i-j的最大边,dp_min[i][j]表示i-j的最小边,可是这样会有问题,有可能最大边与最小边不在同一条路径上,这样就很麻烦了. ...

  7. HDU 1114(没有变形的完全背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 Piggy-Bank Time Limit: 2000/1000 MS (Java/Others ...

  8. HDU ACM 1181 变形课 (广搜BFS + 动态数组vector)-------第一次使用动态数组vector

    http://acm.hdu.edu.cn/showproblem.php?pid=1181 题意:给我若干个单词,若单词A的结尾与单词B的开头相同,则表示A能变成B,判断能不能从b开头变成m结尾. ...

  9. HDU - 1028——母函数入门

    [题目描述] "Well, it seems the first problem is too easy. I will let you know how foolish you are l ...

  10. hdu 1028 母函数 模版题

    母函数详解 http://www.wutianqi.com/?p=596 第二种: 求用1分.2分.3分的邮票贴出不同数值的方案数: 大家把这种情况和第一种比较有何区别?第一种每种是一个,而这里每种是 ...

最新文章

  1. 使用线程池时一定要注意的五个点
  2. 柜位预測(一)——显示柜位曲线图
  3. 前端Yslow的23个优化原则
  4. 用计算机模仿大脑,用计算机复刻大脑
  5. 6条策略提高mysql查询速度 潇湘博客
  6. 惜缘-致家乡的一位女孩[原创]
  7. fm足球经理Football Manager 2022 for mac(真实模拟游戏)中文版
  8. 优化mysql数据库性能的十个参数
  9. 对接支付宝流程【网页支付,手机网页支付,APP支付】
  10. 精密划片机的三种切割方式
  11. 车载网络信号的编码方式
  12. 小升初 择校简历标准
  13. 8.ansible高级进阶-role详解
  14. Ubuntu 版本的命名规则和开发代号
  15. Mixly第26课~第28课,内容抢先看 | Mixly米思齐纯干货系列
  16. c语言整数编年历系统,作为程序员必须知道的编程语言编年史
  17. 到了2020年,年薪80w的阿里P7专家,顶尖的技术人才只因做到了这几点
  18. 小程序时代的来临,另一个战场的开启
  19. 寒假学习心得--从0开始学破解
  20. BLE蓝牙广播包的比特流处理之白噪化和CRC校验

热门文章

  1. 最严格的身份证校验(Java版)
  2. Yii 2.0 权威指南 (6) 请求处理
  3. net.sf.json Sring转JSON对象 数据精度丢失
  4. 31. 连续子数组的最大和
  5. java 进制转换 栈 链表_c语言链表栈实现进制转换
  6. CountDownLatch类使用api
  7. qt设置文本背景透明_QT QWidget设置窗体透明度方法汇总
  8. 大数据Hadoop学习记录(5)----Ubuntu16.4下安装配置HBase
  9. HashMap 的底层源码分析
  10. Spring基于XML的IOC细节