POJ 3187  Backward Digit Sums

http://poj.org/problem?id=3187

题目大意:

给你一个原始的数字序列: 3   1   2   4  他可以相邻的元素相加得到 4 3 6 然后 7 9 最后得到16,现在给定序列的长度,还有最后的得数,求原始序列(多解则取最小)

思路:

直接枚举即可。

下面是next_permutation版本。

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int a[12],sum[12][15]; int main()
{
int n,s;
while(~scanf("%d%d",&n,&s))
{
for(int i=1;i<=10;i++)
a[i]=i; bool find=false;
do
{
memcpy(sum[1],a,sizeof(a));
for(int i=2;i<=n;i++)
for(int j=1;j<=n-i+1;j++)
sum[i][j]=sum[i-1][j]+sum[i-1][j+1]; if(sum[n][1]==s)
break; }while(next_permutation(a+1,a+n+1)); for(int i=1;i<n;i++)
printf("%d ",a[i]);
printf("%d\n",a[n]);
}
return 0;
}

POJ 3187 Backward Digit Sums 枚举水~的更多相关文章

  1. 穷竭搜索:POJ 3187 Backward Digit Sums

    题目:http://poj.org/problem?id=3187 题意: 像这样,输入N : 表示层数,输入over表示最后一层的数字,然后这是一个杨辉三角,根据这个公式,由最后一层的数,推出第一行 ...

  2. poj 3187 Backward Digit Sums(穷竭搜索dfs)

    Description FJ and his cows enjoy playing a mental game. They write down the numbers to N ( <= N ...

  3. POJ 3187 Backward Digit Sums

    暴力DFS+验证. 验证如果是暴力检验可能复杂度会太高,事实上可以o(1)进行,这个可以o(n*n)dp预处理. #include<cstdio> #include<cstring& ...

  4. POJ 3187 Backward Digit Sums (递推,bruteforce)

    第1行j列的一个1加到最后1行满足杨辉三角,可以先推出组合数来 然后next_permutation直接暴. #include<cstdio> #include<iostream&g ...

  5. POJ 3187 Backward Digit Sums (dfs,杨辉三角形性质)

    FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N < ...

  6. Backward Digit Sums(POJ 3187)

    Backward Digit Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5495   Accepted: 31 ...

  7. 【POJ - 3187】Backward Digit Sums(搜索)

    -->Backward Digit Sums 直接写中文了 Descriptions: FJ 和 他的奶牛们在玩一个心理游戏.他们以某种方式写下1至N的数字(1<=N<=10). 然 ...

  8. BZOJ1653: [Usaco2006 Feb]Backward Digit Sums

    1653: [Usaco2006 Feb]Backward Digit Sums Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 207  Solved:  ...

  9. POJ3187 Backward Digit Sums 【暴搜】

    Backward Digit Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4487   Accepted: 25 ...

随机推荐

  1. CSUOJ 1651 Weirdo

    1651: Weirdo Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 40  Solved: 21[Submit][Status][Web Board ...

  2. cogs 50. [NOIP2002] 选数

    50. [NOIP2002] 选数 ★   输入文件:choose.in   输出文件:choose.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述]: 已知 n 个整数 ...

  3. jquery事件 【mousedown与mouseup ----keydown与keypress与keyup】focus--blur--orrer--pageX-pageY

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> ...

  4. IOS 以随意点为圆心 旋转UIView

    环绕底边中点旋转                     UIView本身是支持旋转的,能够用UIView.transform属性实现旋转. The origin of the transform i ...

  5. nagios插件之登陆防火墙实现session监控

    ssh_firewall_session.sh -- 登陆防火墙并运行dis session statistics firewall_check_sessions.c -- 调用上面脚本.过滤出ses ...

  6. Icomparer和Icomparable集合排序

    c#中实现对象集合的排序可以使用ArrayList中的Sort()方法,而有比较才能谈排序,因为不是基本类型(如string ,int.double......等)所以.NET Framework不可 ...

  7. js插件---10个免费开源的JS音乐播放器插件

    js插件---10个免费开源的JS音乐播放器插件 一.总结 一句话总结:各种插件都有很多,多去找. 二.js插件---10个免费开源的JS音乐播放器插件 亲测可用 音乐播放器在网页设计中有时候会用到, ...

  8. UVALive 5292 Critical Links

    Critical Links Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Ori ...

  9. Linux搭建aspx.net环境之:CentOs 7 安装 Mono 和 Jexus 步骤记录

    1 因为163没有CentOs7的镜像.所以没有加这个 wget  http://mirrors.163.com/.help/CentOS6-Base-163.repo cd /etc/yum.rep ...

  10. start_kernel----lcokdep_init

    void lockdep_init(void) { int i; /* * Some architectures have their own start_kernel() * code which ...