3 solutions

  • 0
    @ 2026-1-4 9:31:57

    60pts

    #include<bits/stdc++.h>
    using namespace std;
    const int N=510;
    int f[N],v[N],w[N];
    int main()
    {
    	int n,V;
    	cin>>n>>V;
    	for(int i=1;i<=n;i++)
    	{
    		cin>>w[i]>>v[i];
    	}
    	for(int i=1;i<=n;i++)
    	{
    		for(int j=V;j>=v[i];j--)
    		{
    			f[j]=max(f[j],f[j-v[i]]+w[i]);
    		}
    	}
    	cout<<f[V];
    	return 0;
    } 
    

    Information

    ID
    3026
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    2
    Accepted
    1
    Uploaded By