QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#268991 | #5146. Skills | Terk | ML | 0ms | 0kb | C++14 | 1.4kb | 2023-11-29 09:51:06 | 2023-11-29 09:51:06 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10,W=220;
int n;
int Rem[N][4],Gy[N][W][W][4];
void Max(int &a,int b){
if(b>a) a=b;
}
int nxt(int x){//注意不要直接+1 因为0的话就不会加 所以开个函数算方便
return x==0?0:x+1;
}
int main(){
int t;
cin>>t;
while(t--){
cin>>n;
for(int i=1;i<=n;i++) cin>>Rem[i][1]>>Rem[i][2]>>Rem[i][3];
memset(Gy,-0x3f,sizeof(Gy));
Gy[0][0][0][1]=Gy[0][0][0][2]=Gy[0][0][0][3]=0;
for(int i=0;i<n;i++){
for(int j=0;j<205;j++){
for(int k=0;k<205;k++){
Max(Gy[i+1][nxt(j)][nxt(k)][1],Gy[i][j][k][1]+Rem[i+1][1]-nxt(j)-nxt(k));
Max(Gy[i+1][1][nxt(k)][2],Gy[i][j][k][1]+Rem[i+1][2]-nxt(k)-1);
Max(Gy[i+1][nxt(j)][1][3],Gy[i][j][k][1]+Rem[i+1][3]-nxt(j)-1);
Max(Gy[i+1][1][nxt(k)][1],Gy[i][j][k][2]+Rem[i+1][1]-nxt(k)-1);
Max(Gy[i+1][nxt(j)][nxt(k)][2],Gy[i][j][k][2]+Rem[i+1][2]-nxt(j)-nxt(k));
Max(Gy[i+1][nxt(j)][1][3],Gy[i][j][k][2]+Rem[i+1][3]-nxt(j)-1);
Max(Gy[i+1][nxt(k)][1][1],Gy[i][j][k][3]+Rem[i+1][1]-nxt(k)-1);
Max(Gy[i+1][nxt(j)][1][2],Gy[i][j][k][3]+Rem[i+1][2]-nxt(j)-1);
Max(Gy[i+1][nxt(j)][nxt(k)][3],Gy[i][j][k][3]+Rem[i+1][3]-nxt(j)-nxt(k));
}
}
}
int ans=0;//可以都不选
for(int j=0;j<205;j++){
for(int k=0;k<205;k++){
ans=max(ans,max(Gy[n][j][k][1],max(Gy[n][j][k][2],Gy[n][j][k][3])));
}
}
cout<<ans<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
2 3 1 1 10 1 10 1 10 1 1 5 1 2 3 6 5 4 7 8 9 12 11 10 13 14 15
output:
26 41