https://www.luogu.org/problemnew/show/P1118 看的出来是个dfs 本来打算直接从下到上一顿搜索 但是不会 看了题解才知道系数是个杨辉三角....... 这样就好写了 但是还是踩了一些坑 一开始只有70分 是因为我最后再把a[i]求和 再判断的 改了之后80分...... 加了一个剪枝: if(s>sums) return; 如果当前和大于sum就返回 成功AC #include<bits/stdc++.h> using namespace std…
有这么一个游戏: 写出一个11至NN的排列a_iai​,然后每次将相邻两个数相加,构成新的序列,再对新序列进行这样的操作,显然每次构成的序列都比上一次的序列长度少11,直到只剩下一个数字位置.下面是一个例子: 3,1,2,43,1,2,4 4,3,64,3,6 7,97,9 1616 最后得到1616这样一个数字. 现在想要倒着玩这样一个游戏,如果知道NN,知道最后得到的数字的大小sumsum,请你求出最初序列a_iai​,为11至NN的一个排列.若答案有多种可能,则输出字典序最小的那一个. […
题目描述 FJ and his cows enjoy playing a mental game. They write down the numbers from 11 to N(1 \le N \le 10)N(1≤N≤10) in a certain order and then sum adjacent numbers to produce a new list with one fewer number. They repeat this until only a single num…
题目描述 FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum adjacent numbers to produce a new list with one fewer number. They repeat this until only a single number is lef…
https://www.luogu.org/problem/show?pid=1118#sub 题目描述 FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum adjacent numbers to produce a new list with one fewer number. Th…
#include<iostream> using namespace std ; ; int y[N][N]; int n; int a[N]; bool st[N]; int sum; bool flag; void print() { ; i<=n; i++) cout<<a[i]<<" "; } void dfs(int step,int ans) { if(ans>sum||flag) return ; &&ans…
一上午都在做有关搜索的题目,,, 看到这题之后就直接开始爆搜 结果只有70分, 其余的点硬生生的就是那么WA了. 我的天哪~ 70分代码: #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int n,sum; int ans; ]; ][]; void shuchu() { ; i<=n; i++) cout<<f[][i]<<&quo…
题目链接 思路:设一开始的n个数为a1.a2.a3...an,一步一步合并就可以用a1..an表示出最后剩下来的数,不难发现其中a1..an的系数恰好就是第n层杨辉三角中的数.所以我们可以先处理出第n层杨辉三角中的数,然后根据这一层中的数搜索即可. #include<iostream> #include<cstdio> #include<fstream> #include<algorithm> #include<string> #include&…
数字三角形 题目链接 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+1*4 首先,我们可以发现每个数字被加上的次数是一个杨辉三角形的一行 利用公式C(n,i)=(n-i+1)*C(n,i-1)/i 可以推出系数 然后爆搜,加一点小剪枝 #include<iostream> #include<cstring> #include<cstdlib&g…
题目描述 有这么一个游戏: 写出一个1-N的排列a[i],然后每次将相邻两个数相加,构成新的序列,再对新序列进行这样的操作,显然每次构成的序列都比上一次的序列长度少1,直到只剩下一个数字位置.下面是一个例子: 3 1 2 4 4 3 6 7 9 16 最后得到16这样一个数字. 现在想要倒着玩这样一个游戏,如果知道N,知道最后得到的数字的大小sum,请你求出最初序列a[i],为1-N的一个排列.若答案有多种可能,则输出字典序最小的那一个. [color=red]管理员注:本题描述有误,这里字典序…