博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3187 Backward Digit Sums(穷竭搜索dfs)
阅读量:6436 次
发布时间:2019-06-23

本文共 1458 字,大约阅读时间需要 4 分钟。

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:          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.

Source

 
注意杨辉三角的求法,要用二维来求,其它的就没什么了。。。
 
1 #include
2 #include
3 #include
4 using namespace std; 5 #define N 16 6 int n,sum; 7 int vis[N]; 8 int a[N][N]; 9 int flag;10 bool check(){11 for(int i=1;i
View Code

 

转载地址:http://qoqga.baihongyu.com/

你可能感兴趣的文章
AI、新材料、5G、智慧城市,未来的社会场景在高交会提前上演
查看>>
Facebook开发的一种数据查询语言——GraphQL:安全概述和测试技巧
查看>>
ECS主动运维2.0,体验升级,事半功倍
查看>>
vim 学习方法
查看>>
php token验证范例
查看>>
WebSocket的C++服务器端实现
查看>>
java中两种添加监听器的策略
查看>>
脑洞成现实!AI系统可提前10s预测地震
查看>>
Page页面生命周期——微信小程序
查看>>
Node.js编写CLI的实践
查看>>
Javascript数组对象的方法和属性
查看>>
oracle数据库的启动和停止
查看>>
《LoadRunner没有告诉你的》之七——使用 LoadRunner 连续长时间执行测试,如何保证参数化的数据足够又不会重复?...
查看>>
python easy_install django 安装
查看>>
读《图解HTTP》总结--第六章
查看>>
毕业就能拿到上万薪资的程序员他们都做了啥?
查看>>
最小的k个数
查看>>
iOS技巧之获取本机通讯录中的内容,解析通讯录源代码
查看>>
程序员从零到月薪15K的转变,python200G资料分享
查看>>
DNS域名解析的知识了解
查看>>