[HAOI2008]玩具取名 DP

本文介绍了一种基于WING四个字母的玩具命名算法,通过替换和扩展名字中的字母,生成复杂且独特的玩具名称。算法使用了动态规划方法,考虑了各种可能的字母组合,确保每个名字都是合法且具有创意的。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description
有一套玩具,想给玩具命名。首先他选择WING四个字母中的任意一个字母作为玩具的基本名字。然后他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使得自己的名字能够扩充得很长。


Sample Input
1 1 1 1
II
WW
WW
IG
IIII


Sample Output
IN


水题,没什么好说的。。。


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long LL;
int _min(int x, int y) {return x < y ? x : y;}
int _max(int x, int y) {return x > y ? x : y;}
int read() {
	int s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}

int L[4][4], mp[4][4][4];
char ss[310];
int f[210][210][4];

int getnum(char c) {
	int s;
	if(c == 'W') s = 0;
	if(c == 'I') s = 1;
	if(c == 'N') s = 2;
	if(c == 'G') s = 3;
	return s;
}

int main() {
	int a = read(), b = read(), c = read(), d = read();
	for(int i = 1; i <= a; i++) {
		scanf("%s", ss + 1);
		int h1 = getnum(ss[1]), h2 = getnum(ss[2]);
		if(L[h1][h2] && mp[h1][h2][L[h1][h2]] == 0) continue;
		L[h1][h2]++; mp[h1][h2][L[h1][h2]] = 0;
	}
	for(int i = 1; i <= b; i++) {
		scanf("%s", ss + 1);
		int h1 = getnum(ss[1]), h2 = getnum(ss[2]);
		if(L[h1][h2] && mp[h1][h2][L[h1][h2]] == 1) continue;
		L[h1][h2]++; mp[h1][h2][L[h1][h2]] = 1;
	}
	for(int i = 1; i <= c; i++) {
		scanf("%s", ss + 1);
		int h1 = getnum(ss[1]), h2 = getnum(ss[2]);
		if(L[h1][h2] && mp[h1][h2][L[h1][h2]] == 2) continue;
		L[h1][h2]++; mp[h1][h2][L[h1][h2]] = 2;
	}
	for(int i = 1; i <= d; i++) {
		scanf("%s", ss + 1);
		int h1 = getnum(ss[1]), h2 = getnum(ss[2]);
		if(L[h1][h2] && mp[h1][h2][L[h1][h2]] == 3) continue;
		L[h1][h2]++; mp[h1][h2][L[h1][h2]] = 3;
	} getchar();
	gets(ss + 1); int len = strlen(ss + 1);
	for(int i = 1; i <= len; i++) {
		f[i][i][getnum(ss[i])] = 1;
	}
	for(int ll = 2; ll <= len; ll++) {
		for(int l = 1; l <= len - ll + 1; l++) {
			int r = l + ll - 1;
			for(int k = l; k < r; k++) {
				for(int p1 = 0; p1 < 4; p1++) if(f[l][k][p1]){
					for(int p2 = 0; p2 < 4; p2++) if(f[k + 1][r][p2] && L[p1][p2]){
						for(int u = 1; u <= L[p1][p2]; u++) f[l][r][mp[p1][p2][u]] = 1;
					}
				}
			}
		}
	} bool bk = 0;
	if(f[1][len][0]) bk = 1, printf("W");
	if(f[1][len][1]) bk = 1, printf("I");
	if(f[1][len][2]) bk = 1, printf("N");
	if(f[1][len][3]) bk = 1, printf("G");
	if(!bk) puts("The name is wrong!");
	else puts("");
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值