답안 #438578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
438578 2021-06-28T09:15:15 Z Haidara Knapsack (NOI18_knapsack) C++17
0 / 100
1 ms 716 KB
/* * * * * * * * * *
 *   ID: Haidara   *
 *   LANG: C++17   *
 *   PROB:         *
 * * * * * * * * * */
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i,x,n) for(int i=x;i<n;i++)
#define FOR(i,n) rep(i,0,n)
#define per(i,x,n) for(int i=x;i>n;i--)
#define ROF(i,x) for(int i=x;i>=0;i--)
#define v(i) vector< i >
#define p(i,j) pair< i , j >
#define pii pair<int,int>
#define m(i,j) map< i , j >
#define pq(i) priority_queue< i >
#define ff first
#define all(x) x.begin(),x.end()
#define ss second
#define pp push_back
using namespace std;
const int inf=1LL<<62LL;
const int mod=1e9+7;
const int maxn=100001;
int s,n,v[maxn],w[maxn],k[maxn],dp[maxn][2001];
int solve(int inx=0,int curr=0)
{
    if(dp[inx][curr])
        return dp[inx][curr];
    if(inx==n)
        return 0;
    FOR(i,k[inx])
    {
        if(curr+i*w[inx]<=s)
            dp[inx][curr]=max(dp[inx][curr],solve(inx+1,curr+i*w[inx])+i*v[i]);
        else
            break;
    }
    return dp[inx][curr];
}
signed main()
{
    cin>>s>>n;
    FOR(i,n)
    {
        cin>>v[i]>>w[i]>>k[i];
        k[i]=min(k[i],s);
    }
    cout<<solve();
}

Compilation message

knapsack.cpp:22:18: warning: overflow in conversion from 'long long int' to 'int' changes value from '4611686018427387904' to '0' [-Woverflow]
   22 | const int inf=1LL<<62LL;
      |               ~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -