第1行j列的一个1加到最后1行满足杨辉三角,可以先推出组合数来

然后next_permutation直接暴。

#include<cstdio>
#include<iostream>
#include <iterator>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std; int n,tar;
const int maxn = ;
int a[maxn];
int C[maxn][maxn]; inline bool ok()
{
int re = ;
for(int i = ; i < n; i++){
re += a[i]*C[n-][i];
}
return re == tar;
} //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
for(int i = ; i < maxn; i++){
C[i][] = C[i][i] = ;
for(int j = ; j < i; j++){
C[i][j] = C[i-][j] + C[i-][j-];
}
}
scanf("%d%d",&n,&tar);
for(int i = ; i < n; i++)a[i] = i+;
while(!ok() && next_permutation(a,a+n));
copy(a, a + n, ostream_iterator<int>(cout, " "));
return ;
}

POJ 3187 Backward Digit Sums (递推,bruteforce)的更多相关文章

  1. POJ 3187 Backward Digit Sums 枚举水~

    POJ 3187  Backward Digit Sums http://poj.org/problem?id=3187 题目大意: 给你一个原始的数字序列: 3   1   2   4  他可以相邻 ...

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

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

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

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

  4. POJ 3187 Backward Digit Sums

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

  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. Backward Digit Sums(暴力)

    Backward Digit Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5664   Accepted: 32 ...

随机推荐

  1. 基础篇---memcache

    十分钟学会memcache,比你想象的要简单 转发:https://baijiahao.baidu.com/s?id=1588816843517136163&wfr=spider&fo ...

  2. 清橙 A1210. 光棱坦克

    A1210. 光棱坦克 时间限制:1.0s   内存限制:512.0MB   总提交次数:   AC次数:   平均分:   将本题分享到:        查看未格式化的试题   提交   试题讨论 ...

  3. Unity---DOTween插件学习(2)---设置参数、Ease曲线、回调函数、动画控制函数

    目录 6.Set设置参数 7.Ease曲线 8.回调函数 9.动画控制函数 本文及系列参考于Andy老师的DOTween系列 欢迎大家关注Andy老师 6.Set设置参数 在Unity中添加一个Cub ...

  4. 洛谷 P1547 Out of Hay (最小生成树)

    嗯... 题目链接:https://www.luogu.org/problemnew/show/P1547 思路: 嗯...既然题中已经说了是最小生成树,那么是需要在最小生成树的模板上稍作修改即可.要 ...

  5. SPGroup 和SPUser的常用操作

    http://www.cnblogs.com/gzh4455/archive/2012/03/26/2417854.html private bool RemoveUserFromGroup(stri ...

  6. POJ2758 Checking the Text 哈希

    注意到插入次数挺少的,于是每次暴力重构,然后哈希+二分 #include<cstdio> #include<iostream> #include<algorithm> ...

  7. Nginx实战(三) 日志配置与切割

    访问日志主要记录客户端访问Nginx的每一个请求,格式可以自定义.通过访问日志,你可以得到用户地域来源.跳转来源.使用终端.某个URL访问量等相关信息. Nginx中访问日志相关指令主要有两条,一条是 ...

  8. python模块之datetime方法详细介绍

    datetime Python提供了许多内置模块用于操作时间日期,如calendar,time,datetime,这篇文章主要是对datetime进行汇总,datetime模块的借口实现原则更加直观, ...

  9. JS——变量和函数的预解析、匿名函数、函数传参、return

    JS解析过程分为两个阶段:编译阶段.执行阶段.在编译阶段会将函数function的声明和定义都提前,而将变量var的声明提前,并将var定义的变量赋值为undefined. 匿名函数: window. ...

  10. Gym 101047K Training with Phuket's larvae

    http://codeforces.com/gym/101047/problem/K 题目:给定n<=2000条绳子,要你找出其中三条,围成三角形,并且要使得围成的三角形面积最小 思路: 考虑一 ...