QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#667077#5303. No Bug No GamevcoistntWA 74ms216412kbC++172.0kb2024-10-22 20:58:342024-10-22 20:58:42

Judging History

This is the latest submission verdict.

  • [2024-10-22 20:58:42]
  • Judged
  • Verdict: WA
  • Time: 74ms
  • Memory: 216412kb
  • [2024-10-22 20:58:34]
  • 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][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 i=0;i<=n;i++){
        for(int j=1;j<=k;j++){
            dp[i][j][0]=dp[i][j][1]=-1e18;
        }
    }
    
    dp[0][0][0]=0;  //0个物品,0体积,价值为0

    for(int i=1;i<=n;i++){
        for(int j=0;j<=k;j++){
            //转移状态
            dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][0]);
            dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][1]);
            if(j>=p[i]){
                //能够完全装下
                dp[i][j][0]=max(dp[i][j][0],dp[i-1][j-p[i]][0]+w[i][p[i]]);
                dp[i][j][1]=max(dp[i][j][1],dp[i-1][j-p[i]][1]+w[i][p[i]]);
            }
            for(int now=1;now<=p[i];now++){
                //装部分物品时
                if(j>=now)
                dp[i][j][1]=max(dp[i][j][1],dp[i][j-now][0]+w[i][now]);
            }
        }
    }
    int ans=0;
    //搜一遍所有状态
    for(int i=1;i<=n;i++){
        for(int j=0;j<=k;j++){
            ans=max(ans,dp[i][j][0]);
        }
        //装部分时一定装满了体积为k
        ans=max(ans,dp[i][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: 9796kb

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: 0
Accepted
time: 74ms
memory: 216236kb

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:

68279788

result:

ok 1 number(s): "68279788"

Test #3:

score: -100
Wrong Answer
time: 68ms
memory: 216412kb

input:

3000 3000
7 63414 1471 67699 90007 79945 68096 24021
8 88988 13255 69503 8350 23580 4589 13918 43025
2 7666 45786
2 23237 48565
9 46170 76160 31929 26707 99 76847 64227 82880 99490
8 45937 52389 61039 13440 76101 49424 68485 47682
4 71757 34559 95339 27693
10 55332 93329 61008 26946 44148 73675 3776...

output:

70716942

result:

wrong answer 1st numbers differ - expected: '70716917', found: '70716942'