类型题,01背包问题。
附一个自认为讲的很好的视频
https://www.bilibili.com/video/BV1kp4y1e794
参考代码:
#include<iostream> #include<cstdio> #include<algorithm> #include<string> #include<cmath> #include<vector> #include<set> #include<sstream> #include<cstring> #include<utility> using namespace std; typedef long long ll; typedef long l; const int N = 110; int a[N][3],f[1100]; int main(){ int t,m; scanf("%d%d",&t,&m); for(int i=1;i<=m;i++)scanf("%d%d",&a[i][1],&a[i][2]); for(int i=1;i<=m;i++){ for(int j=t;j>=a[i][1];j--){ f[j]=max(f[j],f[j-a[i][1]]+a[i][2]); } } cout<<f[t]; }
0.0分
0 人评分
剪刀石头布 (C语言代码)浏览:765 |
母牛的故事 (C语言代码)浏览:716 |
简单的a+b (C语言代码)浏览:550 |
C二级辅导-进制转换 (C语言代码)浏览:686 |
矩形面积交 (C语言代码)浏览:1321 |
单词个数统计 (C语言代码)浏览:1015 |
格式化数据输出 (C语言代码)浏览:827 |
输出九九乘法表 (C语言代码)浏览:1078 |
简单的a+b (C语言代码)浏览:473 |
1250题解浏览:561 |