#include<bits/stdc++.h> #define x first #define y second #define PB push_back #define mst(x,a) memset(x,a,sizeof(x)) #define all(a) begin(a),end(a) #define rep(x,l,u) for(ll x=l;x<u;x++) #define rrep(x,l,u) for(ll x=l;x>=u;x--) #define sz(x) x.size() #define IOS ios::sync_with_stdio(false);cin.tie(0); using namespace std; typedef unsigned long long ull; typedef pair<int,int> PII; typedef pair<char,char> PCC; typedef long long ll; typedef pair<ll,ll> PLL; const int N=105; const int M=1e5+10; const int INF=0x3f3f3f3f; const int MOD=1e9+7; int w[N],v[N],f[N][M]; void solve(){ int n,W;cin>>n>>W; int mx=-1; rep(i,1,n+1) cin>>w[i]>>v[i],mx=max(mx,v[i]); f[0][0]=0; int bound=mx*n; rep(i,1,bound+1) f[0][i]=INF; rep(i,1,n+1){ rep(j,0,bound+1){ if(j<v[i]) f[i][j]=f[i-1][j]; else f[i][j]=min(f[i-1][j],f[i-1][j-v[i]]+w[i]); } } ll ans=0; rep(i,0,bound+1) if(f[n][i]<=W) ans=max(ans,i); cout<<ans<<endl; } int main(){ IOS; //freopen("test.txt", "r", stdin); //freopen("test.txt", "w", stdout); //int t;cin>>t; //while(t--) solve(); return 0; }
本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。
我来说两句