穷竭搜索:POJ 3187 Backward Digit Sums
题目:http://poj.org/problem?id=3187
题意:
像这样,输入N : 表示层数,输入over表示最后一层的数字,然后这是一个杨辉三角,根据这个公式,由最后一层的数,推出第一行的数字(由1~N组成)。如果有多个解,按字典序升序,输出第一个解。
题解:水题,不多说
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std; int N, over; void solve()
{
int num[][];
scanf("%d%d", &N, &over); for (int i = ; i <= N; i++) {
num[][i - ] = i;
} do {
for (int i = ; i < N; i++) {
for (int j = ; j < N - i; j++) {
num[i][j] = num[i - ][j] + num[i - ][j + ];
}
}
// cout << "Debug: " << num[N - 1][0] << endl;
if (num[N - ][] == over) {
break;
}
} while (next_permutation(num[], num[] + N)); //本来就是按字典序来搜索的,根本不用考虑题目最后一个条件 →_→,直接输出第一行就可以
for (int i = ; i < N; i++) {
if (i != N - ) {
printf("%d ", num[][i]);
}
else {
printf("%d\n", num[][i]);
}
}
} int main()
{
solve(); 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(穷竭搜索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,杨辉三角形性质)
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+验证. 验证如果是暴力检验可能复杂度会太高,事实上可以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 ...
- 【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 ...
- 《挑战程序设计竞赛》2.1 穷竭搜索 POJ2718 POJ3187 POJ3050 AOJ0525
POJ2718 Smallest Difference Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6509 Acce ...
- 1.初级篇——最基础的"穷竭搜索”
A.Lake Counting(POJ 2386) 题意: 由于最近的降雨,农夫约翰田地的各个地方都有水汇聚,用N x M(1 <= N <= 100; 1 <= M <= 1 ...
随机推荐
- mongodb常用基本命令(根据工作需要,不断更新)
推荐可视化工具:mongobooster 复制库 db.copyDatabase("ability_message","ability_message_cop ...
- 【硬件】- 英特尔CPU命名规则
前言 一款Intel CPU的命名,一般由5个部分组成:品牌,品牌标识符,Gen标识,SKU数值,产品线后缀. 以下图为例: 品牌 英特尔旗下处理器有许多子品牌,包括我们熟悉的凌动(ATOM).赛扬( ...
- [转帖]学习一下centos7 新地方
总结的挺好 copy一下 慢慢学习: http://blog.itpub.net/312079/viewspace-2214440/ Centos7 单用户模式 centos7里不再有0-6启动级别 ...
- HDU4622_Reincarnation
题目给出一个长为2000的字符串,和10000询问,每次询问从第l到第r个字符中间有多少个不同的子串. 其实,全部预处理.f[i][j]表示从i到j个字符的子串数.重构2000遍SAM. 对于新加入的 ...
- python的N个小功能(找到要爬取的验证码链接,并大量下载验证码样本)
# -*- coding: utf-8 -*- """ Created on Mon Mar 21 11:04:54 2017 @author: sl "&qu ...
- 小菜菜mysql练习50题解析——数据准备
附上数据准备: 学生表 create table Student(SId varchar(10),Sname varchar(10),Sage datetime,Ssex varchar(10)); ...
- ldap禁止匿名用户登录
此处默认ldap已经安装完成,安装文档传送门:https://www.cnblogs.com/crysmile/p/9470508.html openldap默认安装完成,是允许匿名用户登录的,因此需 ...
- Netty基础系列(3) --彻底理解NIO
前言 上一节中我们提到了同步异步与阻塞非阻塞的区别,知道了同步并不等于阻塞.而本节的主角NIO是一种同步非阻塞的I/O模型,并且是I/O多路复用模型.NIO在java中被称为 New I/O.它并不能 ...
- oracle 空表导出dmp会报错
步骤一.查找出来的语句全部复制并执行 select 'analyze table '||table_name||' compute statistics;' from user_tables; 步骤二 ...
- 【CF739E】Gosha is hunting(动态规划,凸优化)
[CF739E]Gosha is hunting(动态规划,凸优化) 题面 洛谷 CF 题解 一个\(O(n^3)\)的\(dp\)很容易写出来. 我们设\(f[i][a][b]\)表示前\(i\)个 ...