LCS2021牛客暑期多校训练营4

链接:https://ac.nowcoder.com/acm/contest/11255/C
来源:牛客网
 

题目描述

Let LCS(s1,s2)LCS(s_1,s_2)LCS(s1​,s2​) denote the length of the longest common subsequence (not necessary continuity) of string s1s_1s1​ and string s2s_2s2​.
 

Now give you four integers a,b,c,na,b,c,na,b,c,n, you need to find three lowercase character strings s1,s2,s3s_1,s_2,s_3s1​,s2​,s3​ satisfy that ∣s1∣=∣s2∣=∣s3∣=n|s_1|=|s_2|=|s_3|=n∣s1​∣=∣s2​∣=∣s3​∣=n 

and  LCS(s1,s2)=a,LCS(s2,s3)=b,LCS(s1,s3)=cLCS(s_1,s_2)=a, LCS(s_2,s_3)=b, LCS(s_1,s_3)=cLCS(s1​,s2​)=a,LCS(s2​,s3​)=b,LCS(s1​,s3​)=c.

输入描述:

The first line has four integers a,b,c,na,b,c,na,b,c,n.

0≤a,b,c≤n0\leq a,b,c\leq n0≤a,b,c≤n.

1≤n≤10001\leq n\leq 10001≤n≤1000.

输出描述:

If there is no solution, output "NO" (without double quotation marks).

If there exists solutions, you only need to output any one: output three lines, the i-th line has one strings sis_isi​.

示例1

输入

1 2 3 4

输出

aqcc
abpp
abcc

示例2

输入

1 2 3 3

输出 

NO

题意

 给四个数字a,b,c,n

 LCS(s1,s2)=a,LCS(s2,s3)=b,LCS(s1,s3)=c

先找到a,b,c最小值为t

a+b+c-2*t 大于n的话就不能得到s1s2s3了

然后s1,s2,s3分别加t个‘a’;

s1s2加上a-t个‘b’;

s2s3加上b-t个‘c';

s3s4加上c-t个‘d’;

a中未填满的部分填'e';

b中未填满的部分填'f';

c中未填满的部分填'g';

最后输出s1s2s3即可

#include <iostream>
using namespace std;
int a, b, c, n;

int main()
{
	cin >> a >> b >> c >> n;
	string s1, s2, s3;
	int t = min(min(a, b), c);
	if(a+b+c-2*t > n)
	{
		puts("NO");
		return 0;
	}
	for(int i=0; i<t; i++)
	{
		s1 += "a";
		s2 += "a";
		s3 += "a";
	}
	for(int i=0; i<a-t; i++)
	{
		s1 += "b";
		s2 += "b";
	}
	for(int i=0; i<b-t; i++)
	{
		s2 += "c";
		s3 += "c";
	}
	for(int i=0; i<c-t; i++)
	{
		s1 += "d";
		s3 += "d";
	}
	while(s1.size() < n) s1 += "e";
	while(s2.size() < n) s2 += "f";
	while(s3.size() < n) s3 += "g";
	cout << s1 << endl;
	cout << s2 << endl;
	cout << s3 << endl;
	return 0;
 } 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值