hdu 4602 Partition
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的更多相关文章
- hdu 4602 Partition 数学(组合-隔板法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4602 我们可以特判出n<= k的情况. 对于1<= k<n,我们可以等效为n个点排成 ...
- hdu 4602 Partition (概率方法)
Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 4602 Partition (矩阵乘法)
Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 4602 Partition 矩阵快速幂
Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Proble ...
- 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 ...
- hdu 4602 Partition(矩阵快速幂乘法)
Problem Description Define f(n) , we have =+++ =++ =++ =++ =+ =+ =+ = totally ways. Actually, we wil ...
- 【HDU 4602】Partition
题意 给你一个数n,把它写成几个正整数相加的形式,即把n拆开成若干段,把所有可能的式子里正整数 k 出现的次数取模是多少. 分析 特判 k>=n 的情况. k<n时:问题相当于n个点排一行 ...
- Partition HDU - 4602 (不知道为什么被放在了FFT的题单里)
题目链接:Vjudge 传送门 相当于把nnn个点分隔为若干块,求所有方案中大小为kkk的块数量 我们把大小为kkk的块,即使在同一种分隔方案中的块 单独考虑,它可能出现的位置是在nnn个点的首.尾. ...
- HDU 4651 Partition 整数划分,可重复情况
Partition Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- HDU5869树状数组+gcd预处理
比赛的时候知道用树状数组,但有点乱不知道怎么处理. 统计不同的gcd的个数其实就是用树状数组统计区间内不同的数的模板题啊... 复杂度O(nlogn) #include <bits/stdc++ ...
- jquery.pagination.js分页
参数说明 参数名 描述 参数值 maxentries 总条目数 必选参数,整数 items_per_page 每页显示的条目数 ...
- Python学习(10)元组
目录 Python 元组 访问元组 修改元组 删除元组 元组运算符 元组索引,截取 无关闭分隔符 元组内置函数 Python 元组 Python的元组与列表类似,不同之处在于元组的元素不能修改. 元组 ...
- python利用xmlrpc方式对odoo数据表进行增删改查操作
# -*- encoding: utf-8 -*- import xmlrpclib #导入xmlrpc库,这个库是python的标准库. username ='admin' #用户登录名 pwd = ...
- Java存储过程调用CallableStatement
什么是存储过程? 一个存储过程是一个可编程的函数,它在数据库中创建并保存.它可以有SQL语句和一些特殊的控制结构组成.当希望在不同的应用程序或平台上执行相同的函数,或者封装特定功能时,存储过程是非常有 ...
- 使用DBMS_STATS来收集统计信息【转】
overview Oracle's cost-based optimizer (COB) uses statistics to calculate the selectivity (the fract ...
- TCP拥塞控制
TCP必须使用端到端拥塞控制而不是使网络辅助的拥塞控制,因为IP层不向端系统提供显式的网络拥塞反馈.TCP采用的方法是让每一个发送方根据所感知到的网络拥塞程度来限制其能向连接发送流量的速率. 几个相关 ...
- tomcat集群配置
http://www.finereporthelp.com/help/24/1/3/3.html#a:4.1
- STM8s窗口看门狗
看看窗口看门狗的框图 从图里看出产生复位信号有2个方式: 1 WDGCR寄存器的T6 由1变0,也就是从此寄存器的值从0x40变成0x3F会产生复位信号: 2 当寄存器WDGCR的值大于WDGWR的时 ...
- #array_parents #parents的区别
https://www.drupal.org/node/279246 #array_parents => 一定会反映表单的物理结构 就是该是哪个下面就是哪个下面 不来虚的#parents = ...