题目描述: B. Shaass and Bookshetime limit per test    2 secondsmemory limit per test 256 megabytesinput   standard inputoutput  standard output Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be…
这道题目的意思就是排两排书,下面这排只能竖着放,上面这排可以平着放,使得宽度最小 根据题意可以得出一个结论,放上这排书的Width 肯定会遵照从小到大的顺序放上去的 Because the total thickness of vertical books is fixed it's good to calculate the minimum possible total width of horizontal books. 那么只需要模拟一遍放书的过程即可,不会TLE 不过正统解法是Dp Dp…
题目链接:http://codeforces.com/problemset/problem/294/B 题意: 有n本书,每本书的厚度为t[i],宽度为w[i] (1<=t[i]<=2, 1<=w[i]<=100). 然后让你将所有书按照下面的方式摆放: 在下面放一本书会占用下面t[i]的长度. 在上面放一本书会占用上面w[i]的长度. 最终要保证上面的总长度不超过下面的总长度. 问你下面的总长度最小是多少. 题解: 表示状态: dp[i][j] = min length 表示已经…
题目 记忆化搜索(深搜+记录状态) 感谢JLGG //记忆话搜索 //一本书2中状态,竖着放或者横着放 //初始先都竖着放,然后从左边往右边扫 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ][][];//dp[第几个][厚度][宽度] int n; ],b[]; int rec(int i,int th,int w) { )return dp[i][th][w…
题目链接:http://codeforces.com/contest/294/problem/B B. Shaass and Bookshelf time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Shaass has n books. He wants to make a bookshelf for all his books.…
[CF1097E]Egor and an RPG game(动态规划,贪心) 题面 洛谷 CodeForces 给定一个长度为\(n\)的排列\(a\),定义\(f(n)\)为将一个任意一个长度为\(n\)的排列划分成最少的上升和下降子序列的个数的最大值.现在你要把这个排列\(a\)划分成不超过\(f(S)\)个上升或者下降子序列. 题解 首先不难得出\(f(n)=k-1,k=min\{x|\frac{x(x+1)}{2}>n\}\),这个怎么构造可以自己想想. 那么设当前排列\(a\)的\(L…
[CF183D]T-shirt(动态规划,贪心) 题面 洛谷 CodeForces 题解 \(O(n^2m)\)的暴力懒得写了,比较容易,可以自己想想. 做法是这样的,首先我们发现一个结论: 对于某个颜色(我们就把尺寸当成染色问题好了),如果你拿的个数越多,那么它对于答案的贡献就越来越少.这个东西是显然的,所以这个函数是一个凸函数. 那么这样子就可以贪心,每次选择对于答案贡献最多的一个颜色,然后同时更新一下它下一次再拿的时候对于答案的贡献就好了. 时间复杂度\(O(n^2+nm)\) #incl…
[BZOJ1046]上升序列(动态规划,贪心) 题面 BZOJ 洛谷 题解 我一开始看错题了,一度以为是字典序最小的序列. 最后发现它要求的字典序是位置的字典序最小. 那就很好办了. 设\(f[i]\)表示以\(i\)开头的\(LIS\)长度,用\(BIT\)转移. 然后每次询问暴力贪心即可. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<…
POJ 3659 Cell Phone Network / HUST 1036 Cell Phone Network(最小支配集,树型动态规划,贪心) Description Farmer John has decided to give each of his cows a cell phone in hopes to encourage their social interaction. This, however, requires him to set up cell phone tow…
[CF1133E]K Balanced Teams(动态规划,单调队列) 题面 CF 让你把一堆数选一些出来分成不超过\(K\)组,每一组里面的最大值和最小值之差不超过\(5\),求最多有多少个人元素可以被分组. 题解 设\(f[i][j]\)表示把前\(i\)个数分成\(j\)组的最多人数. 然后单调队列转移一下完了. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring&g…