标签:poj3187
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4487 | Accepted: 2575 |
Description
3 1 2 4 4 3 6 7 9 16Behind FJ‘s back, the cows have started playing a more difficult game, in which they try to determine the starting sequence from only the final total and the number N. Unfortunately, the game is a bit above FJ‘s mental arithmetic capabilities.
Input
Output
Sample Input
4 16
Sample Output
3 1 2 4
Hint
Source
#include <stdio.h> #include <string.h> #include <algorithm> int lev[12][12]; int box[12], N, S; int main() { int i, j, sum; lev[1][1] = 1; for(i = 2; i <= 10; ++i) for(j = 1; j <= i; ++j) if(j == 1 || j == i) lev[i][j] = 1; else lev[i][j] = lev[i-1][j] + lev[i-1][j-1]; while(scanf("%d%d", &N, &S) == 2) { for(i = 1; i <= N; ++i) box[i] = i; do { sum = 0; for(i = 1; i <= N; ++i) sum += box[i] * lev[N][i]; if(sum == S) break; } while(std::next_permutation(box + 1, box + N + 1)); for(i = 1; i <= N; ++i) printf("%d%c", box[i], i == N ? '\n' : ' '); } return 0; }
POJ3187 Backward Digit Sums 【暴搜】
标签:poj3187
原文地址:http://blog.csdn.net/chang_mu/article/details/41012659