90pts 求助 WA on #4
查看原帖
90pts 求助 WA on #4
255077
麦克斯韦の妖楼主2022/8/25 11:42

就是朴素的区间 DP , 猜测问题在读入上

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
const int N=2e5+10;
// W 1
// I 2
// N 3
// G 4
int a,b,c,d,len;
bool dp[250][250][5];
bool tp[5][5][5];
int s[250];
int change(char x)
{
	if(x=='W') return 1;
	if(x=='I') return 2;
	if(x=='N') return 3;
	return 4;
}
char changeII(int x)
{
	if(x==1) return 'W';
	if(x==2) return 'I';
	if(x==3) return 'N';
	return 'G';
}
void Read()
{
    char ch[5];
	for(int i=1;i<=a;i++)
	{
		scanf("%s",ch);
		tp[change(ch[0])][change(ch[1])][1]=1;
	}
	for(int i=1;i<=b;i++)
	{
		scanf("%s",ch);
		tp[change(ch[0])][change(ch[1])][2]=1;
	}
	for(int i=1;i<=c;i++)
	{
		scanf("%s",ch);
		tp[change(ch[0])][change(ch[1])][3]=1;
	}
	for(int i=1;i<=d;i++)
	{
		scanf("%s",ch);
		tp[change(ch[0])][change(ch[1])][4]=1;
	}
	char tmp;	
	while(~scanf("%c",&tmp))
	{
		if(tmp>='A' && tmp<='Z') s[++len]=change(tmp);
	}
}
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&d);
	Read();
	for(int i=1;i<=len;i++)
	{
		dp[i][i][s[i]]=1;
	}
	for(int l=2;l<=len;l++)
	{
		for(int i=1,j;i+l-1<=len;i++)
		{
			j=i+l-1;
			for(int k=i;k<j;k++)
			{
				for(int o=1;o<=4;o++) 
					if(dp[i][k][o])
						for(int p=1;p<=4;p++) 
							if(dp[k+1][j][p])
								for(int q=1;q<=4;q++) 
									if(tp[o][p][q]) 
										dp[i][j][q]=1;
			}
		}
	}
	bool flag=0;
	for(int i=1;i<=4;i++)
	{
		if(dp[1][len][i])
		{
			printf("%c",changeII(i));
			flag=1;
		}
	}
	if(flag==0)
	{
		printf("The name is wrong!\n");
	}
}
2022/8/25 11:42
加载中...