http://acm.hdu.edu.cn/showproblem.php?pid=4602

输入 n 和 k

首先 f(n)中k的个数 等于 f(n-1) 中 k-1的个数

最终等于 f(n-k+1) 中 1 的个数

舍 s(n) = f(n) + f(n-1) + ....+ f(1)

则 f(n) = s(n) - s(n-1)

由于 s(n) = s(n-1) + 2^(n-2) + s(n-1) = 2*(s(n-1)) + 2^(n-2)

= 2^(n-1) + (n-1)*2^(n-2)

       = (n+1)*2^(n-2)

代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<vector>
#include<algorithm>
#include<queue>
#include<stdexcept>
#include<bitset>
#include<cassert>
#include<deque>
#include<numeric> using namespace std; typedef long long ll;
typedef unsigned int uint;
const double eps=1e-12;
const int INF=0x3f3f3f3f;
const ll MOD=1000000007;
ll power(ll x,ll y)
{
ll tmp=1;
while(y)
{
if((y&1))
tmp=(tmp*x)%MOD; x=(x*x)%MOD;
y=y>>1;
}
return tmp;
}
int main()
{
//freopen("data.in","r",stdin);
int T;
cin>>T;
while(T--)
{
ll n,m;
cin>>n>>m;
ll k=n-m+1;
if(k<=0)
{
cout<<"0"<<endl;
continue;
}
if(k==1)
{
cout<<"1"<<endl;
continue;
}
if(k==2)
{
cout<<"2"<<endl;
continue;
}
ll w1=(k+1)*power(2,k-2)%MOD;
--k;
ll w2=(k+1)*power(2,k-2)%MOD;
cout<<(w1-w2+MOD)%MOD<<endl;
}
return 0;
}

hdu 4602 Partition的更多相关文章

  1. hdu 4602 Partition 数学(组合-隔板法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4602 我们可以特判出n<= k的情况. 对于1<= k<n,我们可以等效为n个点排成 ...

  2. hdu 4602 Partition (概率方法)

    Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. HDU 4602 Partition (矩阵乘法)

    Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  4. hdu 4602 Partition 矩阵快速幂

    Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Proble ...

  5. hdu 4602 Partition(快速幂)

    推公式+快速幂 公式有很多形式,可以写矩阵 1.前n-1项和的两倍+2的(n-2)次方,这个写不出啥 2.递推式:f(n)=2*f(n-1)+2的(n-3)次方 3.公式:2的(n-k-2)次方*(n ...

  6. hdu 4602 Partition(矩阵快速幂乘法)

    Problem Description Define f(n) , we have =+++ =++ =++ =++ =+ =+ =+ = totally ways. Actually, we wil ...

  7. 【HDU 4602】Partition

    题意 给你一个数n,把它写成几个正整数相加的形式,即把n拆开成若干段,把所有可能的式子里正整数 k 出现的次数取模是多少. 分析 特判 k>=n 的情况. k<n时:问题相当于n个点排一行 ...

  8. Partition HDU - 4602 (不知道为什么被放在了FFT的题单里)

    题目链接:Vjudge 传送门 相当于把nnn个点分隔为若干块,求所有方案中大小为kkk的块数量 我们把大小为kkk的块,即使在同一种分隔方案中的块 单独考虑,它可能出现的位置是在nnn个点的首.尾. ...

  9. HDU 4651 Partition 整数划分,可重复情况

    Partition Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. [转载]VFS—Kernel Space & User Space

    在了解虚拟文件系统之前 , 需要先了解 Kernel Space 和 User Space 的区别 . 二者的差别在于内存使用上安全机制的差异 . kernel 执行时会占据一段系统的内存空间 , 这 ...

  2. js图片跑马灯效果

    <style. type="text/css">body{margin:0px auto; padding:0px;}ul,li{margin:0px; padding ...

  3. (五)Super VLAN

  4. UIButton的常见设置

    - (void)setTitle:(NSString *)title forState:(UIControlState)state;设置按钮的文字 - (void)setTitleColor:(UIC ...

  5. Bootstrap的标题

    一.定义标题 Bootstrap和普通的HTML页面一样,定义标题都是使用标签<h1>到<h6>,只不过Bootstrap覆盖了其默认的样式,使用其在所有浏览器下显示的效果一样 ...

  6. OpenGL的glClearColor和glClear改变背景颜色

    OpenGL的glClearColor和glClear改变背景颜色 结合以下两个函数void glClearColor(GLclampf red,    GLclampf green, GLclamp ...

  7. 探索 Pexpect,第 1 部分:剖析 Pexpect

    Pexpect 是一个用来启动子程序并对其进行自动控制的 Python 模块. Pexpect 可以用来和像 ssh.ftp.passwd.telnet 等命令行程序进行自动交互.本文章介绍 Pexp ...

  8. Graph-tool简介 - wiki

    graph-tool is a Python module for manipulation and statistical analysis of graphs[disambiguation nee ...

  9. <转> jsp页面向action传值的方法(最后一种简单)

    多的不说,直接上代码; struts.xml代码: <?xml version="1.0" encoding="UTF-8"?> <!DOCT ...

  10. u盘安装ubuntu server 14.04 以及No CD-ROM drive was detected 错误

    u盘安装ubuntu server 14.04 1:下载ubuntu server14的 iso镜像文件 2:下载 UltraISO U盘镜像制作工具 : 3:使用Ultra iOS 将下载好的 is ...