UVA 12563 01背包
来源:互联网 发布:淘宝天天特价在哪里 编辑:程序博客网 时间:2024/05/19 16:48
01背包题目,我们采用滚动数组优化;
对于第二个答案有个限制即n最大所以第二次逆序枚举而且取max时求得
PS:~~我是不会说初始化要为负的
Code:
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#define fo(i,a,b) for(int i=a;i<=b;i++)#define fod(i,a,b) for(int i=a;i>=b;i--)using namespace std;const int T=50*180+678+10,N=50+10;const int inf=0x3f3f3f;int f[T],n,t,a[N],dp[T],num,tot=0;int main(){ scanf("%d",&num); while(num--) { scanf("%d%d",&n,&t); fo(i,1,n) scanf("%d",&a[i]); memset(f,-127,sizeof(f)); f[0]=0; for(int i=1;i<=n;i++) for(int j=t-1;j>=a[i];j--) f[j]=max(f[j],f[j-a[i]]+1); int ans=-inf,tme; for(int i=t-1;i>=0;i--) if(f[i]>ans) ans=f[tme=i]; printf("Case %d: %d %d\n",++tot,ans+1,tme+678); } return 0;}
0 0
- UVA 12563 01背包
- UVA-12563 01背包
- uva 12563(01背包)
- UVa 12563 dp 背包
- uva 562( 01背包)
- uva 624(01背包)
- uva 10130(01背包)
- UVA 11400 01背包
- Uva-10130 SuperSale 01背包
- SuperSale - UVa 10130 01背包
- 【UVA】10130-SuperSale(01背包)
- Dividing coins+uva+01背包
- Homer Simpson+uva+01背包
- UVA 10130 SuperSale(01背包)
- UVA 624 CD (01 背包)
- uva 01背包记录路径
- UVA - 12563 Jin Ge Jin Qu hao (01背包)
- UVA 12563 Jin Ge Jin Qu hao 01背包
- composer 简单应用
- Google Gson的使用方法,实现Json结构的相互转换
- 二进制string转为string
- crontab
- js 取当前时间
- UVA 12563 01背包
- Android Volley完全解析
- 网站设计中致使网站失败的几个最致命错误设计
- 选举游戏
- Appium测试
- Eclipse 反编译插件JadClipse安装
- 查看远程仓库地址
- Hibernate的一级缓存
- ribbon的注解使用报错--No instances available for [IP]