2 条题解

  • 1
    @ 2024-12-11 20:24:39
    #include<bits/stdc++.h>
    using namespace std;
    
    int n,m;
    int f[1010],v[1010],w[1010];
    
    int main()
    {
        cin>>n>>m;
        for(int i = 1;i <= n;i++) cin>>v[i]>>w[i];
        for(int i = 1;i<=n;i++)
            for(int j = v[i];j <= m;j++)
                f[j] = max(f[j],f[j-v[i]]+w[i]);
    
        cout<<f[m]<<endl;
        return 0;
    }
    
    • 0
      @ 2026-6-4 23:09:56
      #include <bits/stdc++.h>
      using namespace std;
      #define int long long
      signed main(){
          ios::sync_with_stdio(false);
          cin.tie(nullptr);
          int n,m;cin>>n>>m;
          vector<int>v(n);
          vector<int>w(n);
          vector<int>result(m+1,0);
          for(int i=0;i<n;i++){
              cin>>v[i]>>w[i];
          }
          for(int i=0;i<n;i++){
              for(int j=v[i];j<=m;j++){
                  result[j]=max(result[j],result[j-v[i]]+w[i]);
              }
          }
          auto ma=max_element(result.begin(),result.end());
          auto M=*ma;
          cout<<M<<endl;
          return 0;
      }
      
      
      • 1

      信息

      ID
      1084
      时间
      1000ms
      内存
      256MiB
      难度
      5
      标签
      递交数
      55
      已通过
      21
      上传者