Last active
October 31, 2016 02:16
-
-
Save ia7ck/072e205fb229702919be792ca3fe8a2e to your computer and use it in GitHub Desktop.
yukicoder No.115 遠足のおやつ
This file contains 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<vector> | |
using namespace std; | |
int memo[101][1001][11]; | |
int N, D, K; | |
vector<int> ans; | |
vector<int> mians; | |
int rec(int i, int s, int m){ | |
if(memo[i][s][m]!=-1) return memo[i][s][m]; | |
if(m==K){ | |
if(s==D){ | |
if(mians.size()==0) mians=ans; | |
return 1; | |
}else{ | |
return 0; | |
} | |
} | |
if(i==N){ | |
return 0; | |
} | |
int ret=0; | |
ans.push_back(i+1); | |
int tukau=rec(i+1, s+(i+1), m+1); | |
ans.pop_back(); | |
int tukawanai=rec(i+1, s, m); | |
ret=(tukau||tukawanai); | |
return memo[i][s][m]=ret; | |
} | |
int main(){ | |
cin>> N>> D>> K; | |
fill((int*)memo, (int*)memo+101*1001*11, -1); | |
if(rec(0, 0, 0)){ | |
for(int i=0; i<mians.size(); i++){ | |
if(i>0){ | |
cout<< " "; | |
} | |
cout<< mians[i]; | |
} | |
cout<< endl; | |
}else{ | |
cout<< -1<< endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment