Codeforces 395 B2. iwiwi
B2. iwiwi
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
The Codeforces users sometimes have very interesting handles! For example, you can meet a grandmaster from Japan named iwiwior an international grandmaster from Taiwan by name 0O0o00OO0Oo0o0Oo.
To be honest, Polycarpus prefers handle iwiwi to 0O0o00OO0Oo0o0Oo.
Polycarpus noticed that in many fonts the width of letter w is exactly twice wider that the width of letter i. Now he wants to write all sorts of strings containing letters i and w on a board exactly as wide as n letters i. He doesn't want the problem to be too easy, so Polycarpus added another limit: each consequence string must be different from the previous one:
either by replacing two consecutive letters i by one letter w,
or be replacing letter w by two consecutive letters i.
For example, string iii can follow after string iw, as the second string results after replacing w by ii in the first one. String wi can follow after string iii, as it is obtained by replacing ii by w.
Help Polycarpus, print all strings of width of exactly n letters i in the described manner. For each pair of consecutive strings there must be exactly one replacement by exactly one of the given rules. The written sequence doesn't have to be cycled, that is, the first string isn't considered consequent for the last string.
Input
The single line of the input contains a positive integer n. The limits for n are different for the subproblems:
for subproblem B1, the following inequation fulfills 1 ≤ n ≤ 5,
for subproblem B2, the following inequation fulfills 1 ≤ n ≤ 20.
Output
Print all strings of letters i and w, such that i + 2w = n, where i — the number of letters i, and w — the number of letters w. Print the strings in the order that is described in the problem.
If there are many answers, print any of them.
Sample test(s)
input
3
output
iw
iii
wi
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<string> vs[30];
int main()
{
vs[1].push_back("i");
vs[2].push_back("ii");
vs[2].push_back("w");
int n;
scanf("%d",&n);
if(n==1) puts("i");
else if(n==2) puts("ii
w");
else
{
int s;
for(int i=3;i<=n;i++)
{
s=vs[i-1].size();
for(int j=s-1;j>=0;j--)
{
vs[i].push_back("i"+vs[i-1][j]);
}
s=vs[i-2].size();
for(int j=s-1;j>=0;j--)
{
vs[i].push_back("w"+vs[i-2][j]);
}
}
s=vs[n].size();
for(int i=0;i<s;i++)
{
cout<<vs[n][i]<<endl;
}
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.