P4290 [HAOI2008]玩具取名

这就是码力的差距,会但是写不出来!!

之后我忘提交了,然后90,当我没说
这还是码力的差距哇!!!

我的90

#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

const int A = 1e7+10;
const int B = 1e3+10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1;
  for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  return x * f;
}
int q[B];
int f[B][B][100];
char cc[5]={'Q','W','I','N','G'};
struct node{char a;char b;}p[5][B],W[B],I[B],N[B],G[B];
char s[B];
int main()
{
	for (int i=1;i<=4;i++) q[i]=read();
	for (int j=1;j<=4;j++)
	for (int i=1;i<=q[j];i++)
	{	
		char ss[5];
		scanf("%s",ss);
		p[j][i].a=ss[0],p[j][i].b=ss[1];
	}
	cin>>s+1;	
	int n=strlen(s+1);
	for (int i=1;i<=n;i++) f[i][i][s[i]-'A'+1]=1;
	for (int len=2;len<=n;len++)
		for (int l=1;l+len-1<=n;l++)
	 	{
		 	int r=l+len-1;
		 	for (int c=1;c<=4;c++)
		 	{
		 		for (int i=1;i<=q[c];i++)
		 		{
					for (int k=l;k<=r;k++)
		 			{	
						if(f[l][k][p[c][i].a-'A'+1] && f[k+1][r][p[c][i].b-'A'+1])		
						f[l][r][cc[c]-'A'+1]=1;
					}
				}
			}	
		 }
	for (int i=1;i<=4;i++) if(f[1][n][cc[i]-'A'+1]) cout<<cc[i];
	return 0;
}



我抄的,区间DP是我的

#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

const int A = 1e7+10;
const int B = 1e3+10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1;
  for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  return x * f;
}

int num[B],p[B*2][3],f[B][B][5];
char s[210];
int check(char i)
{
	if (i=='W') return 1;
	if (i=='I') return 2;
	if (i=='N') return 3;
	if (i=='G') return 4;
}

int main()
{
	int tot=0;
	for (int i=1;i<=4;i++) num[i]=read();
	for (int i=1;i<=4;i++)
	{
		for (int j=1;j<=num[i];j++)
		{
			char ss[5];
			scanf("%s",ss);
			p[++tot][0]=i;
			p[tot][1]=check(ss[0]);
			p[tot][2]=check(ss[1]);
		}
		getchar();
	}
	gets(s+1);
	int len=strlen(s+1);
	for (int i=1;i<=len;i++) f[i][i][check(s[i])]=1;
	for (int l=2;l<=len;l++)
		for (int i=1;i+l-1<=len;i++)
		{
			int j=i+l-1;
			for (int k=i;k<j;k++)
				for (int c=1;c<=tot;c++)
				{
					if (f[i][k][p[c][1]] && f[k+1][j][p[c][2]])
					f[i][j][p[c][0]]=1;
					//printf("%d\n",f[i][j][p[c][0]]);
				}
		} 
//		for(register int i=len;i>0;--i)  
//    	for(register int j=i+1;j<=len;++j)  
//    		for(register int k=i;k<j;++k)  
//    			for(register int l=1;l<=tot;++l)   
//						if (f[i][k][p[l][1]] && f[k+1][j][p[l][2]])
//					f[i][j][p[l][0]]=1;
	int flag=0;
	for (int i=1;i<=4;i++)
	{
		if(f[1][len][i])
		{
			flag=1;
			if (i==1) printf("W");
			if (i==2) printf("I");
			if (i==3) printf("N");
			if (i==4) printf("G");
		}
	}
	if (!flag) printf("The name is wrong!");
	return 0;
}
posted @ 2021-03-27 16:38  zxsoul  阅读(54)  评论(0编辑  收藏  举报