题意:给你一棵高度为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 总结的更多相关文章

  1. Topcoder口胡记 SRM 562 Div 1 ~ SRM 599 Div 1

    据说做TC题有助于提高知识水平? :) 传送门:https://284914869.github.io/AEoj/index.html 转载请注明链接:http://www.cnblogs.com/B ...

  2. TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E

    传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...

  3. 竞赛图的得分序列 (SRM 717 div 1 250)

    SRM 717 DIV 1 中 出了这样一道题: 竞赛图就是把一个无向完全图的边定向后得到的有向图,得分序列就是每个点的出度构成的序列. 给出一个合法的竞赛图出度序列, 要求构造出原图(原题是求(u, ...

  4. TopCoder SRM 667 Div.2题解

    概览: T1 枚举 T2 状压DP T3 DP TopCoder SRM 667 Div.2 T1 解题思路 由于数据范围很小,所以直接枚举所有点,判断是否可行.时间复杂度O(δX × δY),空间复 ...

  5. Topcoder SRM 648 (div.2)

    第一次做TC全部通过,截图纪念一下. 终于蓝了一次,也是TC上第一次变成蓝名,下次就要做Div.1了,希望div1不要挂零..._(:зゝ∠)_ A. KitayutaMart2 万年不变的水题. # ...

  6. SRM 638 Div.2

    250 给一个字符串 要求从一种形式换成另一形式 class NamingConvention{ private: int a, b, c; public: int d; string toCamel ...

  7. [topcoder]SRM 646 DIV 2

    第一题:K等于1或者2,非常简单.略.K更多的情况,http://www.cnblogs.com/lautsie/p/4242975.html,值得思考. 第二题:http://www.cnblogs ...

  8. [topcoder]SRM 633 DIV 2

    第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076 模拟就可以了. #includ ...

  9. 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)是 ...

随机推荐

  1. jquery结合highcharts插件显示实时数据动态曲线图

    效果如图所示: js代码如下: $(document).ready(function() { Highcharts.setOptions({ global: { useUTC: false }, co ...

  2. 正选反选JS

    JS <script> window.onload=function(){ var oTher=document.getElementById('other'); var oCheck=d ...

  3. windbg 调试技巧

    技巧一:在加载名卸载的时候下断点 1. 加载某个DLL 的时候下断点的WinDBG 命令: sxe ld:[dll name] 然后按F5,进行刷新,再使用lmf 查看装载的Dll名称. 2.  卸载 ...

  4. LINUX查看硬件配置命令

    LINUX查看硬件配置命令   系统 # uname -a # 查看内核/操作系统/CPU信息 # head -n 1 /etc/issue # 查看操作系统版本 # cat /proc/cpuinf ...

  5. J2SE知识点摘记(十六)

    1.         IO包中的类层次 ┌BufferedInputStream ├DataInputStream ┌FilterInputStream┼LineNumberInputStream ├ ...

  6. 使用Ramdisk 加速 Visualstudio 编译调试

    一般来说ASP.NET在执行的时候,会先动态编译在目录 C:\Windows\Microsoft.NET\Framework64\版本\Temporary ASP.NET Files 由于每次修改程序 ...

  7. HBuilder的几个常用快捷键

    Alt + [ 匹配括号 Alt + ↓跳转到下一个可编辑区 Ctrl + Alt + j 合并下一行 Ctrl + Alt + ←选择助手 Shift + 回车 Shift + 空格   Ctrl ...

  8. C++ Placement New

    先看一个题目: #include <stdio.h> #include <iostream> using namespace std; struct Base { int j; ...

  9. javascript 中 keyup、keypress和keydown事件

    keyup.keypress和keydown事件都是有关于键盘的事件 1. keydown事件在键盘的键被按下的时候触发,keyup 事件在按键被释放的时候触发    keydown.keypress ...

  10. frameset常用属性

    框架是网页画面分成几个框窗(不同的窗口对应不同页面以几个网页的形式显示),同时取得多个 src的地址.页面所有框架标记需要放在一个总起的 html 档,这个档案只记录了该框架如何分割 ,不会显示任何资 ...