제출 #1129248

#제출 시각아이디문제언어결과실행 시간메모리
1129248newbie__1Knapsack (NOI18_knapsack)C++20
17 / 100
2 ms2192 KiB
#include<bits/stdc++.h> #define ll long long #define F first #define S second #define pb push_back #define mpr make_pair const ll N=2e5 + 10 , mod=1e9 + 7; const double eps=1e-6; using namespace std; ll n,m,a,b,c,s,q,x,k; ll t[N]; string ch; vector<vector<ll>>v; ll res=0; int main(){ // ios_base::sync_with_stdio (0); cin.tie(0),cout.tie(0); // freopen("time.in","r",stdin); // freopen("time.out","w",stdout); ll T=1; //cin>>T; while(T--){ cin>>s>>n; ll v[n+5],w[n+5],c[n+5]; vector<ll>t; for(ll i=0;i<n;i++){ cin>>v[i]>>w[i]>>c[i]; } ll dp[n+20][s+2]; memset(dp,0,sizeof(dp)); dp[0][0]=0; ll res=0; ll x=1; for(ll i=1;i<=n;i++){ for(ll j=0;j<min(s,c[i-1]);j++){ for(ll k=0;k<=s;k++){ dp[x][k]=dp[x-1][k]; if(k>=w[i-1]){ dp[x][k]=max(dp[x][k],dp[x-1][k-w[i-1]]+v[i-1]); } } x++; //cout<<i<<" "<<j<<" "<<dp[i+j][k]<<" \n"; res=max(res,dp[x-1][s]); } } cout<<res<<"\n"; } return 0; } /* 1 41 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...