2 条题解

  • 0
    @ 2025-10-8 17:00:44

    by cff_0102:

    #include<bits/stdc++.h>
    using namespace std;
    const int K=55, V=1e6+5;
    int dp[2][V];
    int main(){
    	ios::sync_with_stdio(0);cin.tie(0);
    	int k, v;cin>>k>>v;
    	for(int i=1;i<=k;i++){
    		int c, s;cin>>c>>s;
    		for(int j=c;j<=v;j++)dp[1][j]=dp[0][j-c];
    		while(s--){
    			int p, e;cin>>p>>e;
    			for(int j=v;j>=c+p;j--){
    				dp[1][j]=max(dp[1][j], dp[1][j-p]+e);
    			}
    		}
    		for(int j=0;j<=v;j++)dp[0][j]=max(dp[0][j], dp[1][j]);
    	}
    	cout<<dp[0][v];
    	return 0;
    }
    
    • 0
      @ 2025-10-8 17:00:38

      by cff_0102:

      #include<bits/stdc++.h>
      using namespace std;
      const int K=55,V=1e6+5;
      int dp[2][V];
      int main(){
      ios::sync_with_stdio(0);cin.tie(0);
      int k,v;cin>>k>>v;
      for(int i=1;i<=k;i++){
      int c,s;cin>>c>>s;
      for(int j=c;j<=v;j++)dp[1][j]=dp[0][j-c];
      while(s--){
      int p,e;cin>>p>>e;
      for(int j=v;j>=c+p;j--){
      dp[1][j]=max(dp[1][j],dp[1][j-p]+e);
      }
      }
      for(int j=0;j<=v;j++)dp[0][j]=max(dp[0][j],dp[1][j]);
      }
      cout<<dp[0][v];
      return 0;
      }

      • 1

      USACO(120)动态规划(背包型)8:电子游戏P2967 [USACO09DEC] Video Game Troubles

      信息

      ID
      2311
      时间
      1000ms
      内存
      128MiB
      难度
      9
      标签
      递交数
      12
      已通过
      6
      上传者