博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ - 3187 Backward Digit Sums(水+全排暴搜)
阅读量:4620 次
发布时间:2019-06-09

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

Backward Digit Sums
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7311   Accepted: 4221

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         16
Behind 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

[]   [Go Back]   []   []

给出第一行数的个数n,然后是第n行的数sum,输出第一行的排列。

思路,枚举1到n的全排列,直到找到一组数成立。

附上AC代码:

#include
using namespace std;int a[15],s[15];int n,N,sum;int main(){ cin>>n>>sum; for(int i=1;i<=n;i++) a[i]=i; do { for(int i=1;i<=n;i++) s[i]=a[i]; for(int i=n;i>1;i--) for(int j=1;j

转载于:https://www.cnblogs.com/l1832876815/p/6771151.html

你可能感兴趣的文章
webpack笔记(4)对图片的处理
查看>>
如果判断一个dom 对像?
查看>>
搜索引擎的反作弊问题
查看>>
nginx lua 01
查看>>
计算机网络 chapter 8 因特网上的音频/视频服务
查看>>
c++输入输出流读取文件
查看>>
Python数据类型之“数字(numerics)”
查看>>
zoj2319Beautiful People Dp
查看>>
图片加载 背景色块问题
查看>>
Static Binding (Early Binding) vs Dynamic Binding (Late Binding)
查看>>
搭建git服务器
查看>>
MYSQL explain详解
查看>>
iOS之UIDynamic UI动力学使用步骤
查看>>
poj 2498 动态规划
查看>>
Windows Phone 7中使用PhoneApplicationService类保存应用程序状态
查看>>
MySql数据库的下载和安装卸载
查看>>
JDBC接口核心的API
查看>>
双缓冲技术局部更新原理之派生自View
查看>>
PPAPI插件与浏览器的通信
查看>>
用 query 方法 获得xml 节点的值
查看>>