每日一题 day14 打卡 Analysis 五维dpf[a1,a2,a3,a4,a5]表示各排从左端起分别占了a1,a2,a3,a4,a5个人时合影方案数量然后我们枚举a1,a2,a3,a4,a5从0开始到N1,N2……N5若a1 < N1若a2 < N2&a1 > a2若a3 < N3&a2 > a3……(以此类推) #include<iostream> #include<cstdio> #include<cstring>…
poj 2279 Mr. Young's Picture Permutations \(solution:\) 首先摘取一些关键词:(每行不超过它后面的行)(每排学生安排高度从左到右减少)(学生的高度应该从后面到前面减少).这个已经很提示我们轮廓线DP了.而且这一题的数据范围也十分的小:行数不超过五行,人数不多于三十人.这么小的数据范围基本上可以断定是DP了. 然后这种带限制条件的我们可以想办法满足,比如说身高问题我们一般都会采取填人的办法(这一题按身高从大到小填(当然反过来也可以)),然后我们…
Description Mr. Young wishes to take a picture of his class. The students will stand in rows with each row no longer than the row behind it and the left ends of the rows aligned. For instance, 12 students could be arranged in rows (from back to front…
[题目链接] http://poj.org/problem?id=2279 [算法] 杨氏矩阵与勾长公式 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #…
[题解]POJ2279 Mr.Young′s Picture Permutations dp 钦定从小往大放,然后直接dp. \(dp(t1,t2,t3,t4,t5)\)代表每一行多少人,判断边界就能dp. 然后你发现\(30^5\)开不下,但是你仔细观察由于它保证\(\sum < 30\)所以你只用开\(30^5 \div 5!\)就好了. 具体为什么我相信你会 //@winlere #include<iostream> #include<cstring> #include…
2483: Pku2279 Mr. Young's Picture Permutations Time Limit: 1 Sec  Memory Limit: 128 MB Description   Mr. Young wishes to take a picture of his class. The students will stand in rows with each row no longer than the row behind it and the left ends of…
POJ2279 Mr Young's Picture Permutations 描述: 有N个学生合影,站成左对齐的k排,每行分别有N1,N2…NK个人,第一排站最后,第k排站之前.学生身高依次是1…N.在合影时候要求每一排从左到右递减,每一列从后面到前也递减,一共有多少总方案输入每组测试数据包含两行.第一行给出行数k. 第二行包含从后到前(n1,n2,…,nk)的行的长度,作为由单个空格分隔的十进制整数. 问题数据以0结束. N<=30, k<=5; 输出 输出每组数据的方案数 样例输入13…
Mr. Young's Picture Permutations 给出一个有k列的网格图,以及每列图形的高度\(n_i\),下端对齐,保证高度递减,设有n个网格,询问向其中填1~n保证每行每列单调递增的方案数,\(n\leq 30,k\leq 5\). 解 事实上,注意到k很小,我们就可以暴力状态了,而要表现单调递增,故维护一个从左至右边矮的阶梯. 以有5列为例,设\(f[a][b][c][d][e]\)表示第1列已经填的数字高度为a,第二列高度为b,...,第5列的高度为e的,现在填到数字\(…
Description Mr. Young wishes to take a picture of his class. The students will stand in rows with each row no longer than the row behind it and the left ends of the rows aligned. For instance, 12 students could be arranged in rows (from back to front…
若干人左对齐站成最多5行,给定每行站多少个,列数从第一排开始往后递减.要求身高从每排从左到右递增(我将题意篡改了便于理解233),每列从前向后递增.每个人身高为1...n(n<=30)中的一个数(互不不同).求可行方案数.(地址点我qwq): 做了lyd书dp这一章的第一题,就不会qwq..果然菜的人还是永远菜啊,注定翻不了身. lyd的书上讲到了dp的方法,不是很理解.后来想通了,发现自己想的时候也想到了这一点转化,但是又很快把他抛弃掉了..冏. 上面所谓的转化就是说,我本来安排人去排列,是无…
问题描述 LG-SP 题解 发现\(n,k\)都非常小,尤其是\(k,k\le 5\),于是直接开\(5\)维进行\(\mathrm{DP}\) 用记忆化搜索实现. \(\mathrm{Code}\) #include<bits/stdc++.h> using namespace std; #define int long long template <typename Tp> void read(Tp &x){ x=0;char ch=1;int fh; while(ch…
题目来源:POJ:http://poj.org/problem?id=2279 SPOJ:https://www.spoj.com/problems/GNYR04H/ 题意翻译 题目描述 杨先生希望为他的班级拍照.学生将排成一行,每行不超过后面的行,并且行的左端对齐.例如,可以安排12名学生排列(从后到前)5,3,3和1名学生. X X X X X X X X X X X X 此外,杨先生希望每排学生安排高度从左到右减少.此外,学生身高应从后向前减少.想想看,杨先生看到,对于这个12人的例子,至…
传送门 Description 杨先生希望为他的班级拍照.学生将排成一行,每行不超过后面的行,并且行的左端对齐.例如,可以安排12名学生排列(从后到前)5,3,3和1名学生. X X X X X X X X X X X X 此外,杨先生希望每排学生安排高度从左到右减少.此外,学生身高应从后向前减少.想想看,杨先生看到,对于这个12人的例子,至少有两种安排学生的方式(数字代表高度,其中1代表最高): 1 2 3 4 5 1 5 8 11 12 6 7 8 2 6 9 9 10 11 3 7 10…
[POJ 2559]Largest Rectangle in a Histogram Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left s…
地址 http://poj.org/problem?id=3253 题解 本题是<挑战程序设计>一书的例题 根据树中描述 所有切割的代价 可以形成一颗二叉树 而最后的代价总和是与子节点和深度相关的 由于切割的次数是确定的 该二叉树的节点就是确定的. 也就是说我们可以贪心的处理  最小长度的子节点放在最下面 如图 ac代码如下 使用了堆 记录每次最小的元素 堆的使用真的不是很方便 , 另外还需要注意 爆int 所以需要使用long long 记录元素的和 #include <iostrea…
The Little Elephant likes permutations. This time he has a permutation A[1], A[2], ..., A[N] of numbers 1, 2, ...,N. He calls a permutation A good, if the number of its inversions is equal to the number of its local inversions. The number of inversio…
题目链接:https://www.luogu.org/problemnew/show/P2279 想怎么贪怎么贪 #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 1010; int n, ans, dis[maxn], dep[ma…
题意:有一排颜色的球,每次选择一个球消去,那么这个球所在的同颜色的整段都消去(和消消乐同理),若消去k个,那么得分k*k,问你消完所有球最大得分 思路:显然这里我们直接用二位数组设区间DP行不通,我们不能表示出“合并”这种情况.我们先把所有小块整理成连续的大块. 我们用click(l,r,len)表示消去l到r的所有大块和r后len块和r颜色一样的小块的最大得分.那么这样我们可以知道,click(l,r,len)只有两种情况: 1.r直接和后面len全都消去 2.r带着len先和前面的一样的颜色…
题意:n*n的网格中有k个点,开一枪能摧毁一行或一列的所有点,问最少开几枪 思路:我们把网格看成两个集合,行集合和列集合,如果有点x,y那么就连接x->y,所以我们只要做最小点覆盖就好了. 参考:POJ3041-Asteroids 代码: #include<set> #include<map> #include<stack> #include<cmath> #include<queue> #include<vector> #in…
题意:问最多有几个括号匹配 思路:用dp[i][j]表示i到j最多匹配,若i和j构成匹配,那么dp[i][j] = dp[i + 1][j - 1] + 2,剩下情况dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j]) 代码: #include<set> #include<map> #include<cmath> #include<queue> #include<cstdio> #include<…
思路: 一开始用Kruskal超时了,因为这是一个稠密图,边的数量最惨可能N^2,改用Prim. Prim是这样的,先选一个点(这里选1)作为集合A的起始元素,然后其他点为集合B的元素,我们要做的就是每次找到B中的一个点,满足这个点到A的权值是B到A的权值中最小的,然后我们把这个点加入到A,再更新B中的点到A的最小距离. 代码: #include<cstdio> #include<cmath> #include<cstring> #include<iostream…
思路: 直接DP也能做,这里用斜率DP. dp[i] = min{ dp[j] + ( sum[i] - sum[j] + 10 )*pr[i]} ; k<j<i  =>  dp[j] - dp[k] <pr[i]*( sum[j] - sum[k] ) 再套模板 #include<queue> #include<cstring> #include<set> #include<map> #include<stack> #i…
Description We will use the following (standard) definitions from graph theory. Let V be a nonempty and finite set, its elements being called vertices (or nodes). Let E be a subset of the Cartesian product V×V, its elements being called edges. Then G…
思路:这题好像以前有类似的讲过,我们把等式移一下,变成 -(a1*x1^3 + a2*x2^3)== a3*x3^3 + a4*x4^3 + a5*x5^3,那么我们只要先预处理求出左边的答案,然后再找右边是否也能得到就行了,暴力的复杂度从O(n^5)降为O(n^3 + n^2).因为左式范围-12500000~12500000,所以至少开12500000 * 2的空间,用int会爆,这里用short.如果小于0要加25000000,这样不会有重复的答案,算是简单的hash? 代码: #incl…
Description The advice to "buy low" is half the formula to success in the bovine stock market.To be considered a great investor you must also follow this problems' advice: "Buy low; buy lower" Each time you buy a stock, you must purcha…
最标准的最小割算法应用题目. 核心思想就是缩边:先缩小最大的边.然后缩小次大的边.依此缩小 基础算法:Prime最小生成树算法 只是本题測试的数据好像怪怪的,相同的算法时间执行会区别非常大,并且一样的代码替换.竟然会WA.系统出错的几率非常小.难倒測试系统本题会有错误? 懒得继续測试这道题的系统了,反正算法正确.AC. #include <stdio.h> #include <string.h> #include <limits.h> const int MAX_N =…
题意: 已知某字符串\(str\)满足\(str_1 > max\{str_2,str_3 \cdots str_n\}\),现要求把这个字符串分成连续的三组,然后每组都翻转,问字典序最小是什么? 思路: 因为\(str_1 > max\{str_2,str_3 \cdots str_n\}\),所以第一部分直接翻转后跑\(sa\)求字典序最小就行了.那么现在问题转化为:把这个字符串分成两半,然后每组都翻转,问字典序最小是什么? 我们假设这个字符串为\(s_1s_2 \cdots s_n\),…
Content 给定两个整数 \(n,m\).定义 \(f(p)=\sum\limits_{l=1}^n\sum\limits_{r=l}^n\min\limits_{i=l}^rp_i\),其中 \(p\) 为一个长度为 \(n\) 的排列.现在,请你求出所有使得 \(f(p)\) 最大的长度为 \(n\) 的排列中,字典序第 \(m\) 小的排列. 数据范围:\(1\leqslant n\leqslant 8\). Solution 看到数据范围马上想到一种很 naive 的 \(O(n!\…
洛谷 P2615 神奇的幻方 洛谷 P2678 跳石头 洛谷 P1226 [模板]快速幂||取余运算 洛谷 P2661 信息传递 LOJ P10147 石子合并 LOJ P10148 能量项链 LOJ P10149 凸多边形的划分 LOJ P10150 括号配对 LOJ P10151 分离与合体 洛谷 P1309 瑞士轮 洛谷 P3956 棋盘 洛谷 P2196 挖地雷 LOJ P10163 Amount of Degrees LOJ P10171 牧场的安排 洛谷 P5020 货币系统 洛谷…
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276,1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740(博弈),1742, 1887, 1926(马尔科夫矩阵,求平衡), 1936, 1952, 1953, 1958, 1959, 1962, 1975,…