洛谷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& ...
随机推荐
- 剑指offer-面试题10-斐波那契数列-递归循环
/* 题目:求斐波那契数列的第n项 */ /* 思路: f(n) = 0 n=0, 1 n=1, f(n-1) + f(n-2) n>1 */ int Fibonacci(int n){ if( ...
- kali linux中mariadb加上密码
kali自带mysql.2019.4 中带得是:MariaDB.据说跟Mysql差不多.简单用了一下发现root用户可以不要密码进入Mysql! 这极不习惯,不输入密码感觉好像少了点什么.这肯定是权限 ...
- xctf-i-got-id-200(perl网页文件+ARGV上传造成任意文件读取)
打开url发现有三个链接,点进去都是.pl文件,且只有files可以上传文件. .pl文件都是用perl编写的网页文件 这里上传了又将文件的内容全部打印出来,那么猜想后台应该用了param()函数. ...
- tmp = 2/4;竟然没有发现的
我还纠结着单目运算符和双目运算符和乘除的一些优先级什么事情. #include "common.h" #include <stdio.h> #include <s ...
- JavaScript仿计算器案例源代码
效果图 index.html <!DOCTYPE html> <html> <head> <title></title> <link ...
- 微信小程序 --- 日历效果
wxml部分: <view class='box1' style='width: {{ sysW * 7 }}px'> <view class='dateBox'>{{ yea ...
- UI中class的用法:
easyui的引入:<link rel="stylesheet" type="text/css" href="easyui/themes/def ...
- npm vs yarn
npm yarn npm install yarn npm install react --save yarn add react npm uninstall react --save yarn re ...
- 获取url参数(jq 扩展包)
(function($){ $.extend({ urlGet:function(url) { var getUrl = url ? url.split("?") : window ...
- HTTPClient模拟Get和Post请求
一.模拟Get请求(无参) 首先导入HttpClient依赖 <dependency> <groupId>org.apache.httpcomponents</group ...