链接: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;
}