洛谷和本地测试不一样啊,本地答案是true的,传上去就Wrong?
查看原帖
洛谷和本地测试不一样啊,本地答案是true的,传上去就Wrong?
222341
twocats楼主2021/3/8 22:02
#include<bits/stdc++.h>
#define N 250
using namespace std;

int p,k,cnt,s,ans,v[N][N],f[N][N];

char str[N];

string S[9];

bool compare(string s,int t)
{
	int l=s.size();
	if(cnt<t+l-1)	return 0;
	for(int i=0;i<l;i++)
	{
		if(s[i]!=str[t+i])
		{
			return 0;
		}
	}
	return 1;
}

void Read()
{
	scanf("%d%d",&p,&k);
	for(int i=1;i<=p;i++)
	{
		for(int j=1;j<=20;j++)
		{
			char c;
			while(true)
			{
				scanf("%c",&c);
				if(c!='\n')	break;
			}
			str[++cnt]=c;
		}
	}
	scanf("%d",&s);
	for(int i=1;i<=s;i++)	cin>>S[i];
}

void Work()
{
	for(int i=1;i<=cnt;i++)
	{
		for(int j=1;j<=s;j++)
		{
			if(compare(S[j],i))
			{
				v[i][i]=1;
			}
		}
	}
	for(int len=2;len<=cnt;len++)
	{
		for(int i=1;i+len-1<=cnt;i++)
		{
			int t=i+len-1;
			v[i][t]=v[i][t-1]+v[t][t];
		}
	}
	for(int len=1;len<=cnt;len++)
	{
		for(int i=1;i<=k;i++)
		{
			for(int j=i;j<=len;j++)
			{
				f[len][i]=max(f[len][i],f[j-1][i-1]+v[j][len]);
			}
		}
	}
}

void Output()
{
	printf("%d",f[cnt][k]);
}

int main()
{
	Read();
	Work();
	Output();
	return 0;
}
2021/3/8 22:02
加载中...