2015 寒假搜索专题 K - Backward Digit Sums
来源:互联网 发布:最好的mac软件下载网站 编辑:程序博客网 时间:2024/05/01 15:54
K - Backward Digit Sums
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uDescription
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.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
首先想到的是给出数字N(N <= 10)与它到1的排列组合。
用dfs把这些数字排列组合保存在数组a中。
每一次的排列组合,用这些数据进行题目意思的相加,得出结果相同就保存,输出这个数组a。
一开始的dfs是从大往下搜,导致后面的数据不符合题目要求。
后来想用个if把整个数组镜像反过来,以为可以水过去,但是结果是又WA了
一次。。。这种思想以后要努力改正。。。
后面是把dfs改成从小往大搜,这样就保证了符合题意的情况下在数组前面的都是较小的那个数。然后就AC了。。。
------------------------------------------------
code:
There are other possible sequences, such as 3 2 1 4, but 3 1 2 4 is the lexicographically smallest.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
首先想到的是给出数字N(N <= 10)与它到1的排列组合。
用dfs把这些数字排列组合保存在数组a中。
每一次的排列组合,用这些数据进行题目意思的相加,得出结果相同就保存,输出这个数组a。
一开始的dfs是从大往下搜,导致后面的数据不符合题目要求。
后来想用个if把整个数组镜像反过来,以为可以水过去,但是结果是又WA了
一次。。。这种思想以后要努力改正。。。
后面是把dfs改成从小往大搜,这样就保证了符合题意的情况下在数组前面的都是较小的那个数。然后就AC了。。。
------------------------------------------------
code:
0 0
- 2015 寒假搜索专题 K - Backward Digit Sums
- pku 3187 Backward Digit Sums搜索
- [暴力搜索] poj 3187 Backward Digit Sums
- POJ3187-Backward Digit Sums-穷竭搜索
- 【暑假复习】【搜索】POJ3187:Backward Digit Sums
- [POJ](3187)Backward Digit Sums ---- 穷竭搜索
- Backward Digit Sums
- POJ3187 Backward Digit Sums
- POJ3187---Backward Digit Sums
- poj3187 Backward Digit Sums
- Backward Digit Sums
- POJ3187-Backward Digit Sums
- Backward Digit Sums POJ3187
- POJ3187 Backward Digit Sums
- poj3187 Backward Digit Sums
- Backward Digit Sums POJ
- Backward Digit Sums
- Backward Digit Sums POJ
- linux文件权限学习笔记
- toad for oracle, 格式化配置 备份FmtPlus.opt
- POJ 2923 Relocation(状压+背包)
- iOS动画进阶(九)图层时间
- Android Chromium:成功地获取到用户自定义的系统默认字体设置
- 2015 寒假搜索专题 K - Backward Digit Sums
- Android Activity学习笔记——Activity的启动和创建
- 同步,异步,阻塞式,非阻塞式联系与区别
- 【稳定婚姻问题】poj3487 The Stable Marriage Problem
- iOS动画进阶(十)缓冲
- 守护进程
- Qu4DQ天伯倫 hulh pSz
- 朱子家训
- uva_232_Crossword Answers