1 #include<cstring>
 2 #include<iostream>
 3 using namespace std;
 4 int main()
 5 {
 6     int i,T,n,m,v,w;
 7     int f[30001];
 8     cin>>T;
 9     while(T--){
10         cin>>n>>m;
11         memset(f,0,(n+1)*sizeof(int));
12         while(m--){
13             cin>>v>>w;
14             for(w*=v,i=n;i>=v;i--)
15                 f[i]=max(f[i],f[i-v]+w);
16         }
17         cout<<f[n]<<endl;
18     }
19     return 0;
20 }

//0-1背包问题

相关文章:

  • 2022-12-23
  • 2021-09-21
  • 2022-12-23
  • 2021-12-13
  • 2021-09-26
  • 2022-12-23
猜你喜欢
  • 2021-09-27
  • 2021-12-17
  • 2022-12-23
  • 2021-08-09
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案