POJ-3187 Backward Digit Sums---枚举全排列
题目链接:
https://vjudge.net/problem/POJ-3187
题目大意:
输入n,sum,求1~n的数,如何排列之后,相邻两列相加,直到得出最后的结果等于sum,输出1~n的排列(杨辉三角)
3 1 2 4 //1~n 全排列中的一个排列
4 3 6
7 9
sum = 16
思路:
直接枚举1-n的全排列,判断之和是不是sum
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<cmath>
using namespace std;
typedef pair<int, int> Pair;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int T, n, m, d;
const int maxn = 1e5 + ;
int a[];
int dir[][] = {,,,,-,,,-};
int Count(int x[])
{
int y[];
for(int i = ; i < n; i++)y[i] = x[i];
for(int i = n - ; i >= ; i--)
{
for(int j = ; j < i; j++)
y[j] = y[j] + y[j + ];
}
return y[];
}
int main()
{
cin >> n >> m;
for(int i = ; i < n; i++)a[i] = i + ;
do
{
if(Count(a) == m)break;
}while(next_permutation(a, a + n));
cout<<a[];
for(int i = ; i < n; i++)cout<<" "<<a[i];
cout<<endl;
return ;
}
POJ-3187 Backward Digit Sums---枚举全排列的更多相关文章
- 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,杨辉三角形性质)
FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N < ...
- 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 (递推,bruteforce)
第1行j列的一个1加到最后1行满足杨辉三角,可以先推出组合数来 然后next_permutation直接暴. #include<cstdio> #include<iostream&g ...
- poj3187-Backward Digit Sums(枚举全排列)
一,题意: 输入n,sum,求1~n的数,如何排列之后,相邻两列相加,直到得出最后的结果等于sum,输出1~n的排列(杨辉三角) 3 1 2 4 //1~n 全排列中的一个排列 4 3 6 7 ...
- 【POJ - 3187】Backward Digit Sums(搜索)
-->Backward Digit Sums 直接写中文了 Descriptions: FJ 和 他的奶牛们在玩一个心理游戏.他们以某种方式写下1至N的数字(1<=N<=10). 然 ...
- Backward Digit Sums(POJ 3187)
Backward Digit Sums Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5495 Accepted: 31 ...
- P1118 [USACO06FEB]Backward Digit Sums G/S
P1118 [USACO06FEB]Backward Digit Sums G/S 题解: (1)暴力法.对1-N这N个数做从小到大的全排列,对每个全排列进行三角形的计算,判断是否等于N. 对每个 ...
随机推荐
- spring session使用日志
请求进入和退出时,filter触发session的提取和保存 getAttribute时会查询数据库 setAttribute会保存到数据库 daemond线程定时自动删除过期的session s ...
- my12_xtrabackup压缩备份与恢复
xtrabackup版本 # rpm -qa | grep xtrabackup percona-xtrabackup-24-2.4.12-1.el7.x86_64 此版本为目前比较新的版本(2018 ...
- php数组·的方法3-数组指针
/* * 数组指针函数 * */ //key() current() 指针一直停在第一位 不会下移 echo '<hr>'; $arr5 = array('name' => 'hxq ...
- java——线段树 SegmentTree
应用: 区间染色 区间查询 线段树不是完全二叉树,线段树是平衡二叉树 使用数组来实现线段树:存储空间为4n 以下是使用数组实现的静态线段树: public class SegmentTree<E ...
- T-SQL 聚合函数Count与NULL
大家都知道聚合函数是做统计用的,而count函数是统计行数的,也就是满足一定条件记录的行数. 下面我们来看下这个count与NULL的微妙关系. CREATE TABLE dbo.Student ( ...
- Django开发常见问题
1.Django设置中文,和时区.静态文件指向 #========================================================== # 设置时区 注意注释上面的:L ...
- sublime text2 for mac 实现json格式化
问题描述: 网上拿下来的一大段json格式的字符串,放到sublime上格式化成json的标准格式 数据截图如下: 解决问题: 网络上搜了一下,大部分都是说要装pretty json插件 先来看看自己 ...
- Java基础06-条件选择语句
1.switch多分支结构 import java.util.Scanner; public class Test1{ public static void main(String[] args){ ...
- Murano Weekly Meeting 2016.07.19
Meeting time: 2016.July.19 1:00~2:00 Chairperson: Kirill Zaitsev, from Mirantis Meeting summary: 1. ...
- Murano Weekly Meeting 2016.05.17
Meeting time: 2016.May.17 1:00~2:00 Chairperson: Kirill Zaitsev, from Mirantis Meeting summary: 1 ...