砖块上的数字最终都可以看作是最后一行的线性组合,独立变元最多9个. 这类题的一般做法,线性组合都可以列出方程然后高斯消元. 对于这道题,只要确定最后一行剩下的4个变量就好了,对于最后一行的j位置,它对上面位置某个数字的和贡献次数 等于它到那个位置路径的方案数,可以发现就是杨辉三角.倒数第二行的数已经足够确定剩下的变量,x到对应位置y的方案是2. x = (y - xleft - xright)/2. /***********************************************…
https://vjudge.net/problem/UVA-11040 找规律 #include<cstdio> using namespace std; ][]; int main() { int T,d; scanf("%d",&T); while(T--) { ;i<=;i++) ;j<=i;j++) scanf(-][j*-]); ;i<=;i+=) { ;j<=;j+=) { a[i][j]=a[i-][j-]-a[i][j-]-…
题意:给定一个金字塔,除了最后一行,每个数都等于支撑它的两个数的和,现在给奇数行的左数奇数位置,求整个金字塔. 析:很容易看出来,从下往上奇数行等于 a[i][j] = (a[i-2][j-1] - a[i][j-1] - a[i][j+1]) / 2;然后偶数行就推出来了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string&…
题意: 45块石头如图排列,每块石头上的数等于下面支撑它的两数之和,求其余未表示的数. 分析: 首先来计算最下面一行的数,A71 = A81 + A82 = A91 + 2A92 + A93,变形得到A92 = (A71 - A91 - A93) / 2. 以此类推,就能得到最下面一整行的数.有了这个“地基”以后,所有的数就都能算出来了. #include <cstdio> ][]; int main() { //freopen("in.txt", "r"…
题目链接:XORwice 题意:给你两个数a.b.求一个数x,使得((a异或x)+(b异或x))这个值最小,输出最小那个x 题解: 输出(a|b)-(a&b)就行(猜了一手 代码: #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<queue> #include<vector> #define mem(x)…
Yup!! The problem name reects your task; just add a set of numbers. But you may feel yourselvescondescended, to write a C/C++ program just to add a set of numbers. Such a problem will simplyquestion your erudition. So, lets add some avor of ingenuity…
A pair of numbers has a unique LCM but a single number can be the LCM of more than one possiblepairs. For example 12 is the LCM of (1, 12), (2, 12), (3,4) etc. For a given positive integer N, thenumber of different integer pairs with LCM is equal to N…
题目链接: 题目 Add All Time Limit:3000MS Memory Limit:0KB 问题描述 Yup!! The problem name reflects your task; just add a set of numbers. But you may feel yourselves condescended, to write a C/C++ program just to add a set of numbers. Such a problem will simply…
Add AgainInput: Standard Input Output: Standard Output Summation of sequence of integers is always a common problem in Computer Science. Rather than computing blindly, some intelligent techniques make the task simpler. Here you have to find the summa…
题意  求把全部数加起来的最小代价  a+b的代价为(a+b) 越先运算的数  要被加的次数越多  所以每次相加的两个数都应该是剩下序列中最小的数  然后结果要放到序列中  也就是优先队列了 #include<cstdio> #include<queue> using namespace std; priority_queue<int, vector<int>, greater<int> >q; typedef long long ll; ll…
题目链接 脑子抽了,看错题了,神奇的看成没有0了.主要问题把n个数插入m个相同的数,把m个数给分成1-m堆,然后插到n+1空里. #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <ctime> #include <cstdlib> #include <iostream> using namespace std;…
题意: 给出n个数,要将n个数相加,每次相加所得的值为当次的计算量,完成所有的求和运算后,要求总的计算量最小. 分析: 直接一个优先队列,由小到大排序,每次前两个相加就好. 代码: #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include<queue>using namespace std;struct cmp{ bool operator…
题意:给你N个数,求把他们的全排列加和为多少 思路:对于这道题,假设数字k1在第一位,然后求出剩下N-1位的排列数num1,我们就可以知道k1在第一位时 排列有多少种为kind1, 同理,假设数字k2在第一位然后求出剩下N-1位的排列数num2, 我们就可以知道k2在第一位时的排列有多少种为kind2, k1*num1+k1*num2.....+kn*numn 就是我们要求的这些数对第一位的所有贡献, 我们知道第一位的贡献=对第二位的贡献=第三位的贡献..... 把所有贡献加和,就能求出结果 知…
题意: 给你一个残缺的塔,每个数字由他下面左右两个数相加得.给你其中一部分,要求输出全部的数字. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; const int maxn = 25; int tmap[25][25]; int main() { int T; scanf("%d",&…
题目链接:UVA-33478 题意为给定n个数,求这n个数能组成的所有不同的排列组成的数字的和. 思路:发现对于任意一个数字,其在每一位出现的次数是相同的.换言之,所有数字的每一位相加的和是相同的. 所以我们只需求出这个“和”即可. 考虑任意一位i,假设我们在i位放置x,则对应\( (n-1)! / ( d_0! * d_1! * ... * d_x! * ... * d_9! ) \)种情况. 所以我们要求的“和”等于\(\sum_x x * (n-1)! / ( d_0! * d_1! *…
题意:给你n个数的集合,每次选两个删除,把它们的和放回集合,直到集合的数只剩下一个,每次操作的开销是那两个数的和,求最小开销. Huffman编码.Huffman编码对于着一颗二叉树,这里的数对应着单词出现的频度,每次合并深度最大的结点,选频度最小的两个. 用两个队列类似归并排序,合并一下. #include<bits/stdc++.h> using namespace std; ; int q1[maxn]; int q2[maxn]; #define GetMin(x)\ if(head1…
贪心   每一次取最小的两个数,注意相加的数也要算' #include<cstring> #include<iostream> #include<cstdio> #include<algorithm> #include<string> #include<queue> using namespace std; int main() { long long a[5005],i; long long b[5005],n; priority_…
[Link]: [Description] 给你长城上的n个修补点,然后你的位置为x; 你需要依次去这n个点,然后把它们全部修好. 但是修的前后顺序不一样的话,花费不一样. 如果立即把第i个点修好的话,需要c[i]点花费; 每多t秒钟,就要多花费t*d[i]点花费. 你一开始的位置在x,然后你的移动速度为v; 求修完所有的点的最小花费. [Solution] 区间动态规划 在任意时刻,你当前的位置,和你之前走的位置肯定是在连续的一段区间上的,因为你不可能跳过一个点不修,而去修它旁边的一个点.因为…
题意:有n(n <= 5000)个数的集合S,每次可以从S中删除两个数,然后把它们的和放回集合,直到剩下一个数.每次操作的开销等于删除的两个数之和,求最小总开销.所有数均小于10^5. 分析:按此操作,最终变成1个数,需要n-1次操作,要想总开销最小,就使每次取出的两数之和最小,优先队列. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cstrin…
There is a brick wall in front of you. The wall is rectangular and has several rows of bricks.The bricks have the same height but different width. You want to draw a vertical line from the top to the bottom and cross the least bricks.The brick wall i…
There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from the top to the bottom and cross the leastbricks. The brick wall…
There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from the top to the bottom and cross the leastbricks. The brick wall…
C - Another Brick in the Wall Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVALive 4425 Description After years as a brick-layer, you've been called upon to analyze the instability of brick walls. The…
http://codeforces.com/contest/1092/problem/D2 Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches. The cur…
[抄题]: There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from the top to the bottom and cross the least bricks. The bric…
传送门:http://codeforces.com/contest/1092/problem/D2 D2. Great Vova Wall (Version 2) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vova's family is building the Great Vova Wall (named by Vo…
There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from the top to the bottom and cross the leastbricks. The brick wall…
We have a grid of 1s and 0s; the 1s in a cell represent bricks.  A brick will not drop if and only if it is directly connected to the top of the grid, or at least one of its (4-way) adjacent bricks will not drop. We will do some erasures sequentially…
[LeetCode]554. Brick Wall 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 题目地址:https://leetcode.com/problems/brick-wall/description/ 题目描述: There is a brick wall in front of you. The wall is rectangular and has…
https://www.quora.com/How-do-I-learn-machine-learning-1?redirected_qid=6578644   How Can I Learn X? Learning Machine Learning Learning About Computer Science Educational Resources Advice Artificial Intelligence How-to Question Learning New Things Lea…