QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#282744#6849. Mr. Liang play Card GameieeAC ✓73ms21168kbC++171.1kb2023-12-12 21:35:272023-12-12 21:35:28

Judging History

你现在查看的是最新测评结果

  • [2023-12-12 21:35:28]
  • 评测
  • 测评结果:AC
  • 用时:73ms
  • 内存:21168kb
  • [2023-12-12 21:35:27]
  • 提交

answer

#include <bits/stdc++.h>

#define N 105

typedef long long ll;

using namespace std;

int a[N],w[N];
ll f[N][N],g[N][N][25][8],pw[N];

int main()
{
	int i,j,k,s,t,T,n,m,u;
	scanf("%d",&T);
	while(T--)
	{
		pw[0]=1;
		scanf("%d %d %d %lld",&n,&m,&u,&pw[1]);u=min(u,7);--u;
		for(i=2;i<=u;++i)pw[i]=pw[i-1]*pw[1];
		for(i=1;i<=n;++i)scanf("%d",&a[i]);
		for(i=1;i<=m;++i)scanf("%d",&w[i]);
		memset(f,-0x3f,sizeof(f));
		memset(g,-0x3f,sizeof(g));
		for(i=0;i<=n;++i)f[i+1][i]=0;
		for(i=1;i<=n;++i){f[i][i]=w[a[i]];g[i][i][a[i]][0]=0;}
		for(i=n;i;--i)
			for(j=i+1;j<=n;++j)
			{
				for(k=1;k<=m;++k)
					for(s=0;s<=u;++s)
					{
						if(s!=0)
							for(t=i;t<j;++t)
								g[i][j][k][s]=max(g[i][j][k][s],g[i][t][k][s-1]+g[t+1][j][k][s-1]);
						else
							for(t=i;t<=j;++t)
								if(a[t]==k)
									g[i][j][k][s]=max(g[i][j][k][s],f[i][t-1]+f[t+1][j]);
						
					}
				for(k=1;k<=m;++k)
					for(s=0;s<=u;++s)
						f[i][j]=max(f[i][j],g[i][j][k][s]+pw[s]*w[k]);
			}
		printf("%lld\n",f[1][n]);
	}
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 73ms
memory: 21168kb

input:

50
55 2 3 8
2 1 2 1 2 2 2 1 1 1 2 2 1 1 2 1 1 2 2 1 1 1 1 1 2 2 1 1 2 2 2 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 2 1 2 2 2 1 1 1
42126 55001
55 3 1 8
2 3 1 1 3 3 3 2 1 2 1 2 1 2 1 3 1 3 3 2 3 2 2 3 1 1 2 2 2 2 2 3 3 2 2 2 3 1 3 2 1 2 2 1 1 2 2 3 3 3 1 1 3 3 2
39105 57552 26545
55 2 3 9
2 1 2 2 2 2 2 2 2 2 ...

output:

38200162
2330529
69176157
3661875
7083386
1021147
334792
859244
1057821
276184
1182470
1200828
1475228
3028111
796232
331782
440245
952455
977955
1210135
51990
1172231
311282
1044444
773077
1426404
4815974
1239955
1144503
120368
84132
2230930
1259948
680475
528194
599850
861273
1739942
1319720
11729...

result:

ok 50 lines