SCU 3172-Fisherman(0-1背包)
来源:互联网 发布:凉宫春日 知乎 编辑:程序博客网 时间:2024/05/29 13:29
D - Fisherman
Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %lluAppoint description:
Description
Time Limit: 1000 MS Memory Limit: 65536 KDescription
Fisherman Zerg has caught N fish and brought them to the fish market. The people from fish market pack the fish in packages with different weights. Each package can have one or more fish. Suppose you are the first customer and you can choose the weight of your package. How many possible different weights of packages exist with these N fish?Input
The first line of the input will be a integer to represent the number of test cases.For each test case there is two lines. The first line contains only one integer N.The second line contains N integers representing the weight of each fish.( 1 <= N <= 30 , 1 <= weight <= 1000 )There is a blank line before each test case.Output
For each test case output the answer on a single line.Sample Input
21505800 200 354 18 182Sample Output
127
题意:
这题说有n条鱼,问你装【1,n】条鱼可以组成多少个不同的重量。
思路:
这题很明显是0-1背包,一开始将每条鱼的重量赋值了,所以答案不正确。但是方法是这样做,最后发现是赋值先会对以后的操作造成影响,所以就将赋值放在了最后面,没想到竟然成功A了。
AC代码:
#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<cstdio>#include<cmath>#include<ctime>#include<cstdlib>#include<queue>#include<vector>#include<set>using namespace std;const int T=30150;#define inf 0x3f3f3f3fL#define mod 1000000000typedef long long ll;typedef unsigned long long ULL;bool v[T];int main(){#ifdef zsc freopen("input.txt","r",stdin); #endifint T,n,i,j,k;scanf("%d",&T);while(T--){memset(v,false,sizeof(v));scanf("%d",&n);for(i=0;i<n;++i){scanf("%d",&k);for(j=30000;j>=k;--j){v[j] |= v[j-k];}v[k] = true;}for(i=0,k=0;i<=30000;++i){if(v[i])k++;}printf("%d\n",k);} return 0;}
0 0
- SCU 3172-Fisherman(0-1背包)
- soj 3172 Fisherman (01背包的装满)
- SCU 2930-积木城堡(n次背包)
- [SCU 4515] 又见背包 (可行性背包DP)
- SCU 4487 king's trouble I(dfs)||(0找1)
- SCU
- SCU
- SCU
- SCU
- 【SCU
- SCU
- SCU
- SCU
- (SCU
- SCU
- SCU
- SCU
- SCU
- iOS制作自己的静态库(即.a文件)
- 51nod 1007 正整数分组 (类01背包问题)
- Git 学习笔记
- git 版本控制和SourceTree的安装使用 eclipse 的egit 插件安装使用
- 1080. Graduate Admission (30)
- SCU 3172-Fisherman(0-1背包)
- hdu1045 Fire Net(dfs水)
- 实战——简易计算器
- javascript & DHTML cookbook摘抄
- LeetCode:Majority Element
- mysql集群搭建教程-基础篇
- NSDate 实现时间格式刚刚、几分钟前、几小时前、昨天、MM-dd HH:mm:ss
- 2015年度总结
- Postgresql 创建用户 可登录 设置权限 配置 远程登录 修改默认用户密码