Created
February 4, 2015 09:44
-
-
Save rohith2506/a854d980239a2a40ef32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <cstring> | |
#include <vector> | |
#include <cmath> | |
using namespace std; | |
int n,k; | |
vector<char> str(35); | |
bool bl[32][32][32][450]; | |
bool dp(int i, int a, int b, int q){ | |
if(i == n){ | |
if(q == k) return 1; | |
return 0; | |
} | |
if(bl[i][a][b][q] == 1) return 0; | |
bl[i][a][b][q] = 1; | |
str[i] = 'A'; | |
if(dp(i+1, a+1, b, q) == 1) return 1; | |
str[i] = 'B'; | |
if(dp(i+1, a, b+1, q+a) == 1) return 1; | |
str[i] = 'C'; | |
if(dp(i+1, a, b, q+a+b) == 1) return 1; | |
return 0; | |
} | |
int main(){ | |
cin >> n >> k; | |
if(dp(0,0,0,0) == 0) | |
cout << "Empty string" << endl; | |
else { | |
string rs = ""; | |
for(int i=0;i<n;i++) rs = rs + str[i]; | |
cout << rs << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment