SRM 585 DIV 1 总结
题意:给你一棵高度为H的完全二叉树的路,问最少需要多少辆车把这路走完,车子不能返回。
那么最优的方案就是从小到上一层层的走完,就很容易地可以得到一种递推,需要注意的就是dp[0] = 1
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime> using namespace std; class TrafficCongestion {
public:
int theMinCars(int);
};
#define LL long long
const int mod = 1000000007;
LL dp[1000005];
int TrafficCongestion::theMinCars(int n) {
dp[0] = 1;
dp[1] = 1;
LL pre = 2;
for(int i = 2;i <= n; i++) {
dp[i] = dp[i-2] + pre;
dp[i] %= mod;
pre = pre*2%mod;
}
return dp[n];
}
给你0到n-1每种数字的数量,问你能构成k个严格递增的序列的方案有多少种,结果对mod取余。
那我们用dp[i][j] 表示放了前i种数字构成j个严格递增的序列的种数,接下来要放第i+1个数字,这里cnt代表前i个数的总数,cur代表i+1的个数,对于j个序列要放 L 个i+1在后面,那剩下的i+1能放的地方有cnt-j+1,剩下i+1的个数为cur-L。我们把cnt-j+1简化成a,cur-L简化成b。
问题就转化成在a个地方放b个东西的方案数,有些地方可以不放东西,那我们就人为地加上a个东西,现在就有a+b个东西了,用a-1的隔板就可以把a+b个东西分成a份,每份中至少有1个东西,可以选择的插隔板的地方有a+b-1个。这就相当于在a个地方放b个东西且有些地方可以不放东西!经典的隔板法!
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define LL long long using namespace std; class LISNumber {
public:
int count(vector <int>, int);
}; LL c[1505][1505], dp[38][1505];
const int mod = 1000000007;
int LISNumber::count(vector <int> card, int K) {
int i, j, l;
c[0][0] = 1;
for(i = 1;i <= 1500; i++) {
c[i][0] = 1;
for(j = 1;j <= i; j++)
c[i][j] = (c[i-1][j] + c[i-1][j-1])%mod;
}
memset(dp, 0, sizeof(dp));
dp[0][card[0]] = 1;
int cnt = card[0];
for(i = 1;i < card.size(); i++) {
int cur = card[i];
for(j = 1;j <= K; j++) {
if(!dp[i-1][j]) continue;
for(l = 0;l <= j; l++) if(cur + j - l <= K && cur >= l)
dp[i][cur-l+j] = (dp[i][cur-l+j] + dp[i-1][j]%mod*c[j][l]%mod*c[cnt+cur-j][cur-l])%mod ;
}
cnt += cur;
}
return dp[card.size()-1][K];
}
SRM 585 DIV 1 总结的更多相关文章
- Topcoder口胡记 SRM 562 Div 1 ~ SRM 599 Div 1
据说做TC题有助于提高知识水平? :) 传送门:https://284914869.github.io/AEoj/index.html 转载请注明链接:http://www.cnblogs.com/B ...
- TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E
传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...
- 竞赛图的得分序列 (SRM 717 div 1 250)
SRM 717 DIV 1 中 出了这样一道题: 竞赛图就是把一个无向完全图的边定向后得到的有向图,得分序列就是每个点的出度构成的序列. 给出一个合法的竞赛图出度序列, 要求构造出原图(原题是求(u, ...
- TopCoder SRM 667 Div.2题解
概览: T1 枚举 T2 状压DP T3 DP TopCoder SRM 667 Div.2 T1 解题思路 由于数据范围很小,所以直接枚举所有点,判断是否可行.时间复杂度O(δX × δY),空间复 ...
- Topcoder SRM 648 (div.2)
第一次做TC全部通过,截图纪念一下. 终于蓝了一次,也是TC上第一次变成蓝名,下次就要做Div.1了,希望div1不要挂零..._(:зゝ∠)_ A. KitayutaMart2 万年不变的水题. # ...
- SRM 638 Div.2
250 给一个字符串 要求从一种形式换成另一形式 class NamingConvention{ private: int a, b, c; public: int d; string toCamel ...
- [topcoder]SRM 646 DIV 2
第一题:K等于1或者2,非常简单.略.K更多的情况,http://www.cnblogs.com/lautsie/p/4242975.html,值得思考. 第二题:http://www.cnblogs ...
- [topcoder]SRM 633 DIV 2
第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076 模拟就可以了. #includ ...
- TopCoder SRM 639 Div.2 500 AliceGameEasy
题意: 一个游戏有n轮,有A和B比赛,谁在第 i 轮得胜,就获得 i 分,给出x,y,问A得x分,B得y分有没有可能,如果有,输出A最少赢的盘数 解题思路: 首先判断n(n+1)/2 = (x+y)是 ...
随机推荐
- js 报错 :object is not a function
object is not a function 我遇到的具体问题是:js命名方法重复了,找到了别的地方,改个方法名就可以了 var h2_price = document.getElementByI ...
- php笔试算法题:顺时针打印矩阵坐标-蛇形算法
这几天参加面试,本来笔试比较简单,但是在面试的时候,技术面试官说让我现场写一个算法,顺时针打印矩阵的坐标,如图所示 顺序为,0,1,2,3,4,9,14,19,24,23,22,21,20,15,10 ...
- 【java】for循环输出数字金字塔
输出下列数字金字塔. 1 121 123211234321 public class deng { public static void main(String args[]) { int n ...
- 从麦肯锡到小黑裙-Project Gravitas |华丽志
从麦肯锡到小黑裙-Project Gravitas |华丽志 从麦肯锡到小黑裙-Project Gravitas
- CF 293 E Close Vertices (树的分治+树状数组)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题目:给出一棵树,问有多少条路径权值和不大于w,长 ...
- css首行缩进两个字符串
text-indent:2em; 这个属性就可以缩进,但是2em不确定是什么意思:抽空总结一下
- 视频日志之android的总结与思考
四月份开始学android,并着手做这个项目,腾讯面试实习忙了半个月没有再做最终铩羽而归.做到5月30日,做了一个交差版,停下了差不多一个月,这两天再捡起完善一点. 项目是做一个视频保存和分享的网站, ...
- android-带进度条的系统通知栏消息
效果图: 主界面只有一个按钮就不上文件了 通知栏显示所用到的布局文件content_view.xml <?xml version="1.0" encoding="u ...
- Java Dom解析xml
Dom解析是将xml文件全部载入,组装成一颗dom树,然后通过节点以及节点之间的关系来解析xml文件,下面结合这个xml文件来进行dom解析. <?xml version="1.0&q ...
- MySQL学习笔记(5)
子查询Subquery 出现在其他sql语句内的select子句. 子查询的外层查询可以是:SELECT,INSERT,UPDATE,SET或DO. 子查询可以返回标量,一行,一列或子查询. ①使用比 ...