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. 对每个 ...
随机推荐
- IOS 11 永不升级方法
解决一直跳苹果升级提示终极解决方法:安装方法很简单,1:进设置-通用-存储空间与iCloud用量-管理储存空间.选择ios xxx 点击他,点删除[如果没有就略过]2:点击:https://oldca ...
- JS电话、手机号码验证
function isTelephone(inpurStr) { var partten = /^0(([1,2]\d)|([3-9]\d{2}))-\d{7,8}$/; ...
- XtraFinder
About System Integrity Protection in OS X 10.11 Apple's article . System Integrity Protection blocks ...
- python3 zip()函数笔记
a=[1,2,3]b=[4,5,6] for A ,B in zip(a,b):#用zip()函数整体打包 print(A,B)
- VMware硬盘空间——扩容
VMware原来分配的硬盘空间太小了--扩容 找到VMware的安装路径,如我是默认安装的:C:\Program Files (x86)\VMware\VMware Workstation,打开该路径 ...
- C++容器嵌套实现动态二维数组(Vector2D)
转: http://blog.csdn.net/Touch_Dream/article/details/74931891 #include<stdio.h> #include <io ...
- mc03_IntelliJ IDEA配置github
配置本地git仓库 首先配置一个本地的git仓库,熟悉一下git上传文件到github的过程,具体操作参考 mc02_配置本地git仓库并上传到github IntelliJ IDEA与github的 ...
- yii1的后台分页和列表
控制器: public function actionIndex(){ $model = new Cases('search'); $model->unsetAttributes(); // c ...
- java——ArrayList 的存在有什么意义?
好像所有的数据类型都可以用比如 TreeMap[] int[] Object[] 这种形式来创建自己的数组,那么ArrayList存在的意义是什么呢? 我只能想到这种:ArrayList可以存储多种 ...
- Hbase 表操作
1. list 操作 2. 创建table column family, 3. 插入数据: put 'user' 3. 检索数据: scan table