QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#670118#5303. No Bug No GamevcoistntWA 49ms73520kbC++171.8kb2024-10-23 20:32:402024-10-23 20:32:41

Judging History

This is the latest submission verdict.

  • [2024-10-23 20:32:41]
  • Judged
  • Verdict: WA
  • Time: 49ms
  • Memory: 73520kb
  • [2024-10-23 20:32:40]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define vcoistnt ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
#define int long long
#define ull unsigned long long
#define lowbit(x) ((x)&-(x))
typedef pair<int,int> pll;
const int N=2e5+10;
const int INF=0x3f3f3f3f3f3f3f3f;
const int inf=INT_MIN;
const int mod=998244353;
const int base=283;
int dp[3030][2]; 
//dp[i][j][0/1]前i件物品,容量为j时的最优,0表示没有取过部分 1表示取过部分
int w[3030][3030],p[3020];
void solve(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>p[i];
        for(int j=1;j<=p[i];j++){
            cin>>w[i][j];
        }
    }
    //初始化,最后一定是恰好完全装满,初始化为-oo

        for(int j=1;j<=k;j++){
            dp[j][0]=dp[j][1]=-1e18;
        }
    
    
    dp[0][0]=0;  //0个物品,0体积,价值为0
    for(int i=1;i<=n;i++){
        for(int j=0;j<=k;j++){
            //转移状态
            dp[j][0]=max(dp[j][0],dp[j][0]);
            dp[j][1]=max(dp[j][1],dp[j][1]);
            if(j>=p[i]){
                //能够完全装下
                dp[j][0]=max(dp[j][0],dp[j-p[i]][0]+w[i][p[i]]);
                dp[j][1]=max(dp[j][1],dp[j-p[i]][1]+w[i][p[i]]);
            }
            for(int now=1;now<=p[i];now++){
                //装部分物品时
                if(j>=now)
                dp[j][1]=max(dp[j][1],dp[j-now][0]+w[i][now]);
            }
        }
    }
    int ans=0;
    //搜一遍所有状态
        for(int j=0;j<=k;j++){
            ans=max(ans,dp[j][0]);
        }
        //装部分时一定装满了体积为k
        ans=max(ans,dp[k][1]);
    cout<<ans;
}
signed main() {
    vcoistnt
    int _=1;
    // cin>>_;
    while(_--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3636kb

input:

4 5
2 1 3
2 1 1
2 3 1
2 1 3

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: -100
Wrong Answer
time: 49ms
memory: 73520kb

input:

3000 3000
10 70562 30723 79371 82224 63977 3362 26909 96449 48163 66159
4 18007 33590 80674 91139
4 10304 31694 70745 50656
10 63090 17226 13187 73881 38137 15237 55750 82751 75854 39658
8 95640 66120 87735 36388 44046 92415 6952 94772
9 60565 27904 98726 87052 35768 25453 14563 34273 92501
10 66332...

output:

299067290

result:

wrong answer 1st numbers differ - expected: '68279788', found: '299067290'