【Poj】-3128-Backward Digit Sums(组合数)
来源:互联网 发布:哪家ui培训好 知乎 编辑:程序博客网 时间:2024/06/17 21:47
Backward Digit Sums
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 7067 Accepted: 4102
Description
FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum adjacent numbers to produce a new list with one fewer number. They repeat this until only a single number is left. For example, one instance of the game (when N=4) might go like this:
Write a program to help FJ play the game and keep up with the cows.
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.
Write a program to help FJ play the game and keep up with the cows.
Input
Line 1: Two space-separated integers: N and the final sum.
Output
Line 1: An ordering of the integers 1..N that leads to the given sum. If there are multiple solutions, choose the one that is lexicographically least, i.e., that puts smaller numbers first.
Sample Input
4 16
Sample Output
3 1 2 4
Hint
Explanation of the sample:
There are other possible sequences, such as 3 2 1 4, but 3 1 2 4 is the lexicographically smallest.
There are other possible sequences, such as 3 2 1 4, but 3 1 2 4 is the lexicographically smallest.
#include <cstdio> #include <algorithm> using namespace std; int c[44][44]; void init() { for(int i=0;i<=12;i++) c[i][i]=1,c[i][0]=1; for(int i=1;i<=12;i++) { for(int j=1;j<i;j++) c[i][j]=c[i-1][j-1]+c[i-1][j];//表示a[i]前面的系数 }} int main() { init(); int n,t; int a[15];while(~scanf("%d%d",&n,&t)){for(int i=1;i<=n;i++)a[i]=i;do{int sum=0;for(int i=1;i<=n;i++) sum+=a[i]*c[n-1][i-1];if(sum==t){for(int i=1;i<n;i++)printf("%d ",a[i]);printf("%d\n",a[n]);break;}}while(next_permutation(a+1,a+1+n));//全排列依次枚举 } return 0; }
0 0
- 【Poj】-3128-Backward Digit Sums(组合数)
- POJ 3187 Backward Digit Sums(next_permutation()+ 组合数)
- Backward Digit Sums POJ
- Backward Digit Sums POJ
- Backward Digit Sums POJ
- POJ 3187 Backward Digit Sums(dfs)
- POJ 3187 Backward Digit Sums (BFS)
- poj--3187--Backward Digit Sums(dfs)
- 【POJ】3187 - Backward Digit Sums(枚举)
- POJ 3187:Backward Digit Sums(dfs)
- POJ 3187 Backward Digit Sums (杨辉三角,穷竭搜索,组合数,DFS)
- POJ 3187 Backward Digit Sums
- POJ 3187 Backward Digit Sums
- POJ 3187 Backward Digit Sums
- poj 3187 Backward Digit Sums
- POJ-3187-Backward Digit Sums
- poj 3187 Backward Digit Sums
- POJ-3187-Backward Digit Sums
- 没有上司的舞会
- Xcode instruments 之 Time Profiler的使用
- 使用cocoapods导入第三方类库后头文件没有代码提示的情况
- JS windows.open打开窗口并居中
- cmd压缩和解压jar文件
- 【Poj】-3128-Backward Digit Sums(组合数)
- Unity Shader基础
- spring cache
- Linux下用c语言实现发送http请求
- JAVA中ListIterator和Iterator的详解与辨析
- XStream解析xml的特殊字符支持
- java中final方法
- 外部参数名
- oracle trunc()函数的用法