Nguyen Hai Long
@hlongng2002241
Viet Nam, Hai Phong
Institution: student
#include <bits/stdc++.h> #define forinc(a,b,c) for(int a=b;a<=c;++a) #define fordec(a,b,c) for(int a=b;a>=c;--a) #define two(n) (1<<n) #define getbit(x,i) ((x>>(i-1))&1) #define onbit(x,i) (x|(1ll<<(i-1))) #define offbit(x,i) (x&~(1ll<<(i-1))) using namespace std; const int gain[]={0,1,1,2,1,2,2,3}; const int mask1[]={0,4,0,4,1,5,1,5}; const int mask2[]={0,2,5,7,2,2,7,7}; int a[110],f[110][8][8],g[110][8][8]; int n; int main() { cin>>n; forinc(i,1,n) { cin>>a[i]; a[i]--; a[i]=a[i]<0?0:(1<<a[i]); } f[1][a[1]][a[2]]=0;g[1][a[1]][a[2]]=1; forinc(i,1,n) forinc(tt,0,7) if (a[i]==0||(tt&a[i])) forinc(tt2,0,7) if (a[i+1]==0||(tt2&a[i+1])) { if (g[i][tt][tt2]==0) continue; int &tg=f[i][tt][tt2]; forinc(p,1,7) if ((p&tt)==0) { int t1=tt2|mask1[p],t2=a[i+2]|mask2[p]; int &tg2=f[i+1][t1][t2]; if (tg2<tg+gain[p]) { tg2=tg+gain[p]; g[i+1][t1][t2]=g[i][tt][tt2]; } else if (tg2==tg+gain[p]) g[i+1][t1][t2]+=g[i][tt][tt2]; } } int res=0,cnt=0; forinc(i,0,7) forinc(j,0,7) if (res<f[n+1][i][j]) { res=f[n+1][i][j]; cnt=g[n+1][i][j]; } else if(res==f[n+1][i][j]) cnt+=g[n+1][i][j]; cout<<res<<" "<<cnt; } QB GAME: #include <bits/stdc++.h> #define forinc(a,b,c) for(int a=b;a<=c;++a) #define fordec(a,b,c) for(int a=b;a>=c;--a) #define two(n) (1<<n) #define getbit(x,i) ((x>>(i-1))&1) #define onbit(x,i) (x|(1ll<<(i-1))) #define offbit(x,i) (x&~(1ll<<(i-1))) using namespace std; long long n,a[20001][9]; long long f[20001][9][257],res=0,mi=INT_MIN; bool ok=false; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); freopen("QBGAME.inp","r",stdin); freopen("QBGAME.out","w",stdout); cin>>n; long long o=(1<<8)-1; forinc(i,1,8) forinc(j,1,n) cin>>a[j][i]; forinc(i,1,8) forinc(j,1,n) { mi=max(mi,a[j][i]); if(a[j][i]>=0) ok=true; } if(ok) { forinc(i,0,n) forinc(j,1,8) forinc(tt,0,o) f[i][j][tt]=INT_MIN; f[0][8][0]=0; forinc(i,0,n) forinc(j,1,8) forinc(tt,0,o) { if(j<8) { forinc(to,0,1) { if(to==0) { long long tt2=offbit(tt,j+1); f[i][j+1][tt2]=max(f[i][j+1][tt2],f[i][j][tt]); } if(to==1) { long long tt2; if(!getbit(tt,j+1)&&!getbit(tt,j)) { tt2=onbit(tt,j+1); f[i][j+1][tt2]=max(f[i][j+1][tt2],f[i][j][tt]+a[i][j+1]); } } } } if(j==8) { forinc(to,0,1) { if(to==0) { long long tt2=offbit(tt,1); f[i+1][1][tt2]=max(f[i+1][1][tt2],f[i][j][tt]); } if(to==1) { long long tt2; if(!getbit(tt,1)) { tt2=onbit(tt,1); f[i+1][1][tt2]=max(f[i+1][1][tt2],f[i][j][tt]+a[i+1][1]); } } } } } forinc(i,0,n) forinc(j,0,8) forinc(tt,0,o) res=max(res,f[i][j][tt]); cout<<res; } else cout<<mi; }
Các lần nộp bài đã được ghi nhân(Xem dạng tệp tin văn bản)
Problems
Danh sách các bài đã làm đạt yêu cầu:
Danh sách các bài làm chưa đạt yêu cầu:
BIGNUM | QBSORT | |||||
C11KM |