ZOJ 2972(背包dp)
来源:互联网 发布:mesh网络 编辑:程序博客网 时间:2024/05/16 14:51
dp[ i ][ j ]表示处于第i个栏,体力为j时所消耗的时间。
有了这个,后面的注意一下细节就好做了。
#include<cstdio>#include<iostream>#include<cstring>using namespace std;const int INF=1e9;int dp[120][120];int t1[120],t2[120],t3[120],f1[120],f3[120];int main(){ int n,T,i,j,m; cin>>T; while(T--) { cin>>n>>m; for(i=1; i<=n; i++) { cin>>t1[i]>>t2[i]>>t3[i]>>f1[i]>>f3[i]; } memset(dp,-1,sizeof(dp)); dp[0][m]=0; for(i=1; i<=n; i++) { for(j=0; j<=m; j++) if(dp[i-1][j]!=-1) { if(j>=f1[i]) { if(dp[i][j-f1[i]]==-1) dp[i][j-f1[i]]=dp[i-1][j]+t1[i]; else dp[i][j-f1[i]]=min(dp[i][j-f1[i]],dp[i-1][j]+t1[i]); } if(dp[i][j]==-1) dp[i][j]=dp[i-1][j]+t2[i]; else dp[i][j]=min(dp[i][j],dp[i-1][j]+t2[i]); if(dp[i][min(m,j+f3[i])]==-1) dp[i][min(m,j+f3[i])]=dp[i-1][j]+t3[i]; else dp[i][min(m,j+f3[i])]=min(dp[i-1][j]+t3[i],dp[i][min(m,j+f3[i])]); } } int _min=INF; for(i=0; i<=m; i++) if(dp[n][i]!=-1) { _min=min(_min,dp[n][i]); } cout<<_min<<endl; } return 0;}
0 0
- ZOJ 2972(背包dp)
- ZOJ 3682 简单dp 背包
- zoj 2972 Hurdles of 110m(dp,背包)
- ZOJ 2972-Hurdles of 110m(背包dp)
- ZOJ-3264 Present for MM (背包dp)
- ZOJ 2972 (DP)
- ZOJ 3626 Treasure Hunt I(树型DP+01背包)
- ZOJ 3201 Tree of Tree(树形背包DP)
- zoj 3201 Tree of Tree(树形背包dp)
- zoj 3626 Treasure Hunt I(树形DP+分组背包)
- ZOJ 3769 —— Diablo III(背包,DP)
- ZOJ-3682 E - Cup 3 DP+01背包
- ZOJ 3201 Tree of Tree(树形dp + 分组背包)
- ZOJ 2109 FatMouse' Trade (背包 dp + 贪心)
- ZOJ 3703 Happy Programming Contest 0-1背包 DP
- ZOJ 3450 Doraemon's Railgun (DP·分组背包)
- ZOJ-3211-Dream City-DP背包问题+贪心
- ZOJ 3956 Course Selection System (dp 01背包)
- POJ 3342 树形DP入门题
- javascript中数组Array的方法
- servlet&jsp 登陆,根据输入显示不同页面内容
- 3分钟入睡治疗术的作用
- poj 1961 Period
- ZOJ 2972(背包dp)
- HIVE RCFile高效存储结构
- 数据结构之链表实现增删改查
- 各种贴片封装尺寸图_百度文章
- 串口打印调试
- Prototype in C++: Before and after
- easytouch的使用
- Shell的文件操作函数SHFileOperation
- poj 3904 Sky Code 莫比乌斯反演 或 容斥原理