类型题,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 人评分
不需要数组和指针的做法!!!浏览:1126 |
【出圈】 (C++代码)(典型的约瑟夫环——链表解决)浏览:1214 |
C二级辅导-求偶数和 (C语言代码)浏览:629 |
川哥的吩咐 (C语言代码)浏览:875 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:525 |
C语言考试练习题_排列 (C语言代码)浏览:1326 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:901 |
A+B for Input-Output Practice (VI) (C++代码)浏览:417 |
ASCII帮了大忙浏览:749 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:685 |