洛谷 [P1118] IOI1994 数字三角形】的更多相关文章

简单dfs 我们注意到,题目中的运算方式与杨辉三角极其相似,所以说本题实际上是一道加权的杨辉三角,搜索系数 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cstdlib> #include <cmath> using namespace std; int init(){ int rv=0,fh=1; cha…
数字三角形 题目链接 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…
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…
洛谷p1216 IOI1994 Day1T1 洛谷原题 题目描述 观察下面的数字金字塔. 写一个程序来查找从最高点到底部任意处结束的路径,使路径经过数字的和最大.每一步可以走到左下方的点也可以到达右下方的点. 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 在上面的样例中,从7 到 3 到 8 到 7 到 5 的路径产生了最大 输入输出格式 输入格式: 第一个行包含 R(1<= R<=1000) ,表示行的数目. 后面每行为这个数字金字塔特定行包含的整数. 所有的被供应的整数是非负…
「洛谷P1043」数字游戏 日后再写 代码 /*#!/bin/sh dir=$GEDIT_CURRENT_DOCUMENT_DIR name=$GEDIT_CURRENT_DOCUMENT_NAME pre=${name%.*} g++ -O2 $dir/$name -o $pre -g -Wall -std=c++11 if test $? -eq 0; then gnome-terminal -x bash -c "time $dir/$pre;echo;read;" fi*/ #…
洛谷1118 数字三角形游戏 题目描述 有这么一个游戏: 写出一个1-N的排列a[i],然后每次将相邻两个数相加,构成新的序列,再对新序列进行这样的操作,显然每次构成的序列都比上一次的序列长度少1,直到只剩下一个数字位置.下面是一个例子:     3   1   2   4       4   3   6         7   9          16 最后得到16这样一个数字. 现在想要倒着玩这样一个游戏,如果知道N,知道最后得到的数字的大小sum,请你求出最初序列a[i],为1-N的一个…
洛谷 第一次找规律A了一道紫题,写篇博客纪念一下. 这题很明显是数位dp,但是身为蒟蒻我不会呀,于是就像分块打表水过去. 数据范围是\(10^{12}\),我就\(10^6\)一百万一百万的打表. 于是我就发现了一些规律. 先献给大家一个打表程序吧- #include <bits/stdc++.h> using namespace std; int main() { long long l,r,cnt[10]={}; for (long long t=0;t<=999999;++t) {…
BZOJ原题链接 洛谷原题链接 又是套记搜模板的时候.. 对\(0\sim 9\)单独统计. 定义\(f[pos][sum]\),即枚举到第\(pos\)位,前面枚举的所有位上是当前要统计的数的个数之和为\(sum\). #include<cstdio> #include<cstring> using namespace std; typedef long long ll; const int N = 13; ll f[N][N]; int a[N], nw; inline ll…
洛谷很早以前就写过了,今天交到bzoj发现TLE了. 检查了一下发现自己复杂度是错的. 题目传送门:洛谷P3704. 题意简述: 求 \(\prod_{i=1}^{N}\prod_{j=1}^{M}F_{\gcd(i,j)}\bmod mod\) ,其中 \(F_{i}\) 是斐波那契数列的第 \(i\) 项, \(mod=10^9+7\) . \(T\) 组数据. 题解: 喜闻乐见的推式子时间. 不失一般性,假设 \(N\le M\) . \[\begin{aligned}&\prod_{i=…