hdu 1709 母函数变形
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 10010
int c1[MAX], c2[MAX], num[110];
/* 题目大意: 给你n种砝码,从1到n中砝码的重量和其中不能称出多少种重量,输出不能称出的总数和类别*/
int main()
{
int n;
while( scanf("%d", &n)!=EOF )
{
memset(num, 0, sizeof(num) );
memset(c1, 0, sizeof(c1) );
memset(c2, 0, sizeof(c2) );
int total = 0;
for(int i=0; i<n; i++) //重量输入
{scanf("%d", &num[i]); total+=num[i];}
//for(int i=0; i<=total; i++)
//c1[i] = c2[i] = 0;
c1[0] = 1; //第一个括号,重量为0的
for(int i=0; i<n; i++)
{
for(int j=0; j<=total; j++)
{
c2[j] |= c1[j]; //否能称得,自己砝码的重量
if(num[i] + j <=total) //重量和是否大于总重量
c2[j+num[i]] |= c1[j]; //重量和
c2[abs(j-num[i])] |= c1[j]; //重量差
}
for(int j=0; j<=total; j++) //一次循环赋值
{c1[j] = c2[j]; c2[j] = 0;}
}
int count = 0;
for(int i=0; i<=total; i++) //查找能否称得的重量
{
if(!c1[i])
c2[count++] = i;
}
printf("%d\n", count);
for(int i=0; i<count-1; i++)
printf("%d ", c2[i]);
if(count) printf("%d\n", c2[count-1]);
}
return 0;
}
/*
Problem Description
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.
Input
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.
Output
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.
Sample Input
3
1 2 4
3
9 2 1
Sample Output
0
2
4 5
*/
附件列表
转载于:https://www.cnblogs.com/sober-reflection/p/030bcb6e395767a11e6c170a46e258f7.html
hdu 1709 母函数变形相关推荐
- hdu 1709 (母函数,有些特殊)
点击打开链接 母函数.. #include"stdio.h" #include"string.h" int main() {int a[10008];int b ...
- HDOJ HDU 1709 The Balance ACM 1709 IN HDU
//MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址 : http://acm.hdu.edu.cn/showproblem.php?pid=1 ...
- HDU2110 Crisis of HDU【母函数】
Crisis of HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 5087(LIS变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5087 解题思路:这道题其实仔细想想很简单,次长LIS只有两种可能,一种就是等于LIS-1,一种就是LI ...
- hdu 5410(背包问题变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5410 解题思路:令dp[i][j][0]表示前i种物品,共j钱,不买第i种物品所能买到的最大值.dp[ ...
- hdu 1598(最小生成树变形)
解题思路:这道题我一开始的思路是动规,dp_max[i][j]表示i-j的最大边,dp_min[i][j]表示i-j的最小边,可是这样会有问题,有可能最大边与最小边不在同一条路径上,这样就很麻烦了. ...
- HDU 1114(没有变形的完全背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 Piggy-Bank Time Limit: 2000/1000 MS (Java/Others ...
- HDU ACM 1181 变形课 (广搜BFS + 动态数组vector)-------第一次使用动态数组vector
http://acm.hdu.edu.cn/showproblem.php?pid=1181 题意:给我若干个单词,若单词A的结尾与单词B的开头相同,则表示A能变成B,判断能不能从b开头变成m结尾. ...
- HDU - 1028——母函数入门
[题目描述] "Well, it seems the first problem is too easy. I will let you know how foolish you are l ...
- hdu 1028 母函数 模版题
母函数详解 http://www.wutianqi.com/?p=596 第二种: 求用1分.2分.3分的邮票贴出不同数值的方案数: 大家把这种情况和第一种比较有何区别?第一种每种是一个,而这里每种是 ...
最新文章
- 使用线程池时一定要注意的五个点
- 柜位预測(一)——显示柜位曲线图
- 前端Yslow的23个优化原则
- 用计算机模仿大脑,用计算机复刻大脑
- 6条策略提高mysql查询速度 潇湘博客
- 惜缘-致家乡的一位女孩[原创]
- fm足球经理Football Manager 2022 for mac(真实模拟游戏)中文版
- 优化mysql数据库性能的十个参数
- 对接支付宝流程【网页支付,手机网页支付,APP支付】
- 精密划片机的三种切割方式
- 车载网络信号的编码方式
- 小升初 择校简历标准
- 8.ansible高级进阶-role详解
- Ubuntu 版本的命名规则和开发代号
- Mixly第26课~第28课,内容抢先看 | Mixly米思齐纯干货系列
- c语言整数编年历系统,作为程序员必须知道的编程语言编年史
- 到了2020年,年薪80w的阿里P7专家,顶尖的技术人才只因做到了这几点
- 小程序时代的来临,另一个战场的开启
- 寒假学习心得--从0开始学破解
- BLE蓝牙广播包的比特流处理之白噪化和CRC校验
热门文章
- 最严格的身份证校验(Java版)
- Yii 2.0 权威指南 (6) 请求处理
- net.sf.json Sring转JSON对象 数据精度丢失
- 31. 连续子数组的最大和
- java 进制转换 栈 链表_c语言链表栈实现进制转换
- CountDownLatch类使用api
- qt设置文本背景透明_QT QWidget设置窗体透明度方法汇总
- 大数据Hadoop学习记录(5)----Ubuntu16.4下安装配置HBase
- HashMap 的底层源码分析
- Spring基于XML的IOC细节