站外水题求助
  • 板块灌水区
  • 楼主pies_0x
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/6/25 17:05
  • 上次更新2024/6/25 20:41:11
查看原帖
站外水题求助
964645
pies_0x楼主2024/6/25 17:05

#include<cstdio>
#include<iostream>
#include<cstring>
#include<memory.h>
using namespace std;

#define N 1050
#define LEN 4050
#define int long long
#define min(a,b) ((a)<(b)?(a):(b))

char s[LEN],t[N][LEN];
int dp[LEN];
int n;

inline bool check(int i,int j)
{
	if(dp[i-strlen(t[j]+1)]==0x3f3f3f3f3f3f3f3f)
		return 0;
	for(int k=1;k<=strlen(t[j]+1);++k)
		if(s[i-strlen(t[j]+1)+k]!=t[j][k])
			return 0;
	return 1;
}

signed main()
{
    int tt;
    scanf("%lld",&tt);
    while(tt--)
    {
    	cin.getline(s+1,LEN);
    	scanf("%lld",&n);
    	cin.ignore();
    	memset(dp,0x3f,sizeof dp);
    	for(int i=1;i<=n;++i)
    		cin.getline(t[i]+1,LEN);
    	dp[0]=0;
    	for(int i=1;i<=strlen(s+1);++i)
    		for(int j=1;j<=n&&strlen(t[j]+1)<=i;++j)
    		{
    			if(!check(i,j))
    				continue;
    			dp[i]=min(dp[i],dp[i-strlen(t[j]+1)]+1);
    		}
    	printf("%lld\n",(dp[strlen(s+1)]==0x3f3f3f3f3f3f3f3f?0:dp[strlen(s+1)]));
    }
    return 0;
}

hack:

1
ogoeom
4
e
r
usssik
oab

正解输出居然是 11!

2024/6/25 17:05
加载中...