洛谷P1118 [USACO06FEB]数字三角形`Backward Digit Su`…
#include<iostream>
using namespace std ;
const int N=;
int y[N][N];
int n;
int a[N];
bool st[N];
int sum;
bool flag;
void print() {
for(int i=; i<=n; i++)
cout<<a[i]<<" ";
}
void dfs(int step,int ans) {
if(ans>sum||flag) return ;
if(step==n+&&ans==sum) {
print();
flag=;
return ;
}
for(int i=; i<=n; i++) {
if(!st[i]) {
st[i]=;
a[step]=i;
dfs(step+,ans+i*y[n][step]);
st[i]=;
}
}
}
int main() {
cin>>n>>sum;
y[][]=;
for(int i=; i<=n; i++)//杨辉三角
for(int j=; j<=i; j++)
y[i][j]=y[i-][j-]+y[i-][j];
dfs(,);
return ;
}
洛谷P1118 [USACO06FEB]数字三角形`Backward Digit Su`…的更多相关文章
- 洛谷—— P1118 [USACO06FEB]数字三角形Backward Digit Su…
https://www.luogu.org/problem/show?pid=1118#sub 题目描述 FJ and his cows enjoy playing a mental game. Th ...
- P1118 [USACO06FEB]数字三角形`Backward Digit Su`… 回溯法
有这么一个游戏: 写出一个11至NN的排列a_iai,然后每次将相邻两个数相加,构成新的序列,再对新序列进行这样的操作,显然每次构成的序列都比上一次的序列长度少11,直到只剩下一个数字位置.下面是一 ...
- P1118 [USACO06FEB]数字三角形`Backward Digit Su`…
题目描述 FJ and his cows enjoy playing a mental game. They write down the numbers from 11 to N(1 \le N \ ...
- P1118 [USACO06FEB]数字三角形Backward Digit Su…
题目描述 FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N ...
- P1118 [USACO06FEB]数字三角形`Backward Digit Su`… (dfs)
https://www.luogu.org/problemnew/show/P1118 看的出来是个dfs 本来打算直接从下到上一顿搜索 但是不会 看了题解才知道系数是个杨辉三角....... 这样就 ...
- Luogu P1118 [USACO06FEB]数字三角形 Backward Digit Sums | 搜索、数学
题目链接 思路:设一开始的n个数为a1.a2.a3...an,一步一步合并就可以用a1..an表示出最后剩下来的数,不难发现其中a1..an的系数恰好就是第n层杨辉三角中的数.所以我们可以先处理出第n ...
- luoguP1118 [USACO06FEB]数字三角形`Backward Digit Su`… 题解
一上午都在做有关搜索的题目,,, 看到这题之后就直接开始爆搜 结果只有70分, 其余的点硬生生的就是那么WA了. 我的天哪~ 70分代码: #include<iostream> #incl ...
- 【洛谷P1118】数字三角形
数字三角形 题目链接 4 16 3 1 2 4 3 1 2 4 (3+1) (1+2) (2+4)(3+1+1+2) (1+2+2+4) (3+1+1+1+2+2+2+4)16=1*3+3*1+3*2 ...
- 洛谷 [P1118] IOI1994 数字三角形
简单dfs 我们注意到,题目中的运算方式与杨辉三角极其相似,所以说本题实际上是一道加权的杨辉三角,搜索系数 #include <iostream> #include <cstdio& ...
随机推荐
- xctf-i-got-id-200(perl网页文件+ARGV上传造成任意文件读取)
打开url发现有三个链接,点进去都是.pl文件,且只有files可以上传文件. .pl文件都是用perl编写的网页文件 这里上传了又将文件的内容全部打印出来,那么猜想后台应该用了param()函数. ...
- Google Chrome 退出清除浏览数据
版本 79.0.3945.88(正式版本) (64 位) 设置-高级-隐私设置和安全性-网站设置-Cookie和网站数据-退出Chrome时清除Cookie及网站数据.
- luogu P1736 创意吃鱼法
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #i ...
- Redis基础详解
1. Redis是什么.特点.优势 Redis是一个开源的使用C语言编写.开源.支持网络.可基于内存亦可持久化的日志型.高性能的Key-Value数据库,并提供多种语言的API. 它通常被称为 数据结 ...
- 0级搭建类005-Oracle Solaris Unix安装 (11.4) 公开
项目文档引子系列是根据项目原型,制作的测试实验文档,目的是为了提升项目过程中的实际动手能力,打造精品文档AskScuti. 项目文档引子系列目前不对外发布,仅作为博客记录.如学员在实际工作过程中需提前 ...
- 解决linux 终端UnicodeDecodeError: 'utf-8' codec can't decode byte 0xce in position 0: invalid continuation byte
vi /etc/locale.conf 修改LANG="zh_CN.gbk" 最后执行source /etc/locale.conf 即可永久生效,下次登录,中文就不会乱码了.
- jQuery---scrollTop和scrollLeft的方法
scrollTop和scrollLeft的方法 <script src="jquery-1.12.4.js"></script> <script> ...
- gtid环境下mysqldump对于set-gtid-purged的取值
gtid环境备份的时候,还在为set-gtid-purged=0|1的选择而烦恼吗,一起来分析一下. [mysql@lxd-vm1@/home/mysql]$ mysqldump --help | g ...
- Verilog-异步FIFO
参考博文:https://blog.csdn.net/alangaixiaoxiao/article/details/81432144 1.概述 异步FIFO设计的关键是产生“写满”和“读空”信号,这 ...
- Spring boot unable to determine jdbc url from datasouce
1. 首先删除 @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) 2. 在配置文件里添加完整的dataso ...