POJ 3187 Backward Digit Sums (递推,bruteforce)
第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)的更多相关文章
- POJ 3187 Backward Digit Sums 枚举水~
POJ 3187 Backward Digit Sums http://poj.org/problem?id=3187 题目大意: 给你一个原始的数字序列: 3 1 2 4 他可以相邻 ...
- 穷竭搜索:POJ 3187 Backward Digit Sums
题目:http://poj.org/problem?id=3187 题意: 像这样,输入N : 表示层数,输入over表示最后一层的数字,然后这是一个杨辉三角,根据这个公式,由最后一层的数,推出第一行 ...
- poj 3187 Backward Digit Sums(穷竭搜索dfs)
Description FJ and his cows enjoy playing a mental game. They write down the numbers to N ( <= N ...
- POJ 3187 Backward Digit Sums
暴力DFS+验证. 验证如果是暴力检验可能复杂度会太高,事实上可以o(1)进行,这个可以o(n*n)dp预处理. #include<cstdio> #include<cstring& ...
- 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 < ...
- Backward Digit Sums(POJ 3187)
Backward Digit Sums Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5495 Accepted: 31 ...
- 【POJ - 3187】Backward Digit Sums(搜索)
-->Backward Digit Sums 直接写中文了 Descriptions: FJ 和 他的奶牛们在玩一个心理游戏.他们以某种方式写下1至N的数字(1<=N<=10). 然 ...
- BZOJ1653: [Usaco2006 Feb]Backward Digit Sums
1653: [Usaco2006 Feb]Backward Digit Sums Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 207 Solved: ...
- Backward Digit Sums(暴力)
Backward Digit Sums Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5664 Accepted: 32 ...
随机推荐
- 老男孩Day1作业(一):编写登录接口
需求:编写登陆接口1. 用户输入帐号密码进行登陆2. 用户信息保存在文件内3. 用户密码输入错误三次后锁定用户 1)编写思路 编写思路参考下面GitHub链接中的流程图 https://github. ...
- Educational Codeforces Round 48 (Rated for Div. 2) D 1016D Vasya And The Matrix (构造)
D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- thinkphp5.1页面页面模板及参数配置
success和error跳转的模板在thinkphp/tpl/dispatch_jump.tpl 配置参数在thinkphp\library\traits\controller\jump.php文件 ...
- ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)
传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...
- 033 Search in Rotated Sorted Array 搜索旋转排序数组
假设按照升序排序的数组在预先未知的某个关键点上旋转.(即 0 1 2 4 5 6 7 将变成 4 5 6 7 0 1 2).给你一个目标值来搜索,如果数组中存在这个数则返回它的索引,否则返回 -1.你 ...
- (转)Linux系统基础网络配置老鸟精华篇
Linux系统基础网络配置老鸟精华篇 原文:http://blog.51cto.com/oldboy/784625 对于linux高手看似简单的网络配置问题,也许要说出所以然来也并不轻松,因此仍然有太 ...
- Oozie安装的说明
不多说,直接干货! Oozie相当于Hadoop的一个客户端,因此集群中要有一台机器部署Oozie server端即可,由于可以有任意多个客户端连接Oozie,故每个客户端都必须部署Oozie cli ...
- vs2017 运行所选代码生成器时出错
[转]https://blog.csdn.net/sunshineyang1205/article/details/80211313 ASPNET MVC Core中像Controller中添加控制器 ...
- 【Linux】Xshell-Linux常用命令
(1)命令ls——列出文件 ls -la 给出当前目录下所有文件的一个长列表,包括以句点开头的“隐藏”文件 ls a* 列出当前目录下以字母a开头的所有文件 ls -l *.doc 给出当前目录下以. ...
- Nginx负载均衡与反向代理的配置实例
user www www; worker_processes 10; error_log /data1/logs/nginx_error.log crit; pid /usr/local/webser ...