UVA56201背包简单版
来源:互联网 发布:sql语句字段增加约束 编辑:程序博客网 时间:2024/04/30 04:27
这题可以往01背包上面想,一个DP思想的简单题。
注意数组不要越界,我就因为这样WA了几发。
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cctype>#include<cmath>#include<algorithm>#include<string>#include<map>#include<queue>#include<stack>#include<set>#include<vector>#define LL long longusing namespace std;const int maxn=1e5+10;const double eps=1e-6;//const int MAX_INT=(1<<31)-1;int main(){ int n,m; cin>>n; int a[110]; int d[50010]; while(n--) { cin>>m; int sum=0; for(int i=0;i<m;i++) { cin>>a[i]; sum+=a[i]; } memset(d,0,sizeof(d)); d[0]=1; for(int i=0;i<m;i++) for(int j=sum;j-a[i]>=0;j--) { if(d[j-a[i]]) d[j]=1; } int ans=50001; for(int i=0;i<=sum;i++) if(d[i]) { ans=min(ans,abs(sum-i-i)); } cout<<ans<<endl; } return 0;}
0 0
- UVA56201背包简单版
- 简单背包
- 初识dp(简单背包)JAVA版
- 简单01背包 完全背包
- 简单背包问题
- 简单的背包问题
- 简单的背包问题
- 简单的01背包
- poj2634 简单01背包
- zoj 3689 简单背包
- 简单背包问题
- 简单的01背包
- 简单的01背包!!
- 简单的01背包!
- 简单0.1背包问题
- 简单背包题
- 简单背包问题
- 简单:01背包问题
- 第5章 进程的通信
- 使用Android API最佳实践
- Flask需求文件重新生成虚拟环境
- 【経験談】VS2013创建数据库连接失败问题
- powerdesigner16.5链接MySQL数据库-win7 64bit
- UVA56201背包简单版
- 视图的移动,旋转,缩放
- CocoaPods 使用
- 认识与学习bash
- 通信协议 - HTTP、TCP、UDP
- TypeError: object of type 'NoneType' has no len()
- tfs配置
- 接口隔离原则(ISP--Interface Segregation Principle)
- python脚本执行linux命令