HUD-4602 Partition 排列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4602
把n等效为排成一列的n个点,然后就是取出其中连续的k个点。分两种情况,一种是不包含两端,2^( n−k−2 ) ∗ (n−k−1) ,另一种是包含两端:2 ∗ 2^( n – k − 1)。然后特殊情况特判一下。。
//STATUS:C++_AC_31MS_248KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const LL INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int T,n,m; LL Pow(LL n,int m)
{
LL ret=;
for(;m;m>>=){
if(m&)ret=(ret*n)%MOD;
n=(n*n)%MOD;
}
return ret;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
if(m>n)
printf("0\n");
else if(n==m)
printf("1\n");
else
printf("%I64d\n",(Pow(,n-m)+(m<n-?(n-m-)*Pow(,n-m-):))%MOD);
}
return ;
}
HUD-4602 Partition 排列的更多相关文章
- 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 ...
- 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 ...
- Oracle 在线重定义表分区
==================原始表================原始表=====================原始表 create table BUILDING_temp(building ...
- 【 2013 Multi-University Training Contest 1 】
HDU 4602 Partition f[i]表示和为i的方案数.已知f[i]=2i-1. dp[i]表示和为i,k有多少个.那么dp[i]=dp[1]+dp[2]+...+dp[i-1]+f[i-k ...
随机推荐
- sparkR原理
p.p1 { margin: 0.0px 0.0px 10.0px 0.0px; font: 11.0px "Times New Roman"; min-height: 12.0p ...
- 【DB】SQLiteHelper
/// <summary> /// 说明:这是一个针对System.Data.SQLite的数据库常规操作封装的通用类. /// </summary> public class ...
- IOS中将十进制色值转换成UIColor
最近因项目需要,在网上找了一些代码,整合了一下,实现的效果就是将10进制的RGB色值转换IOS用的UIColor,方法还有缺陷,有待改进 UIColor *getColorFromString(NSS ...
- Linux命令总结(转载)
转子:http://www.cnblogs.com/CGDeveloper/archive/2011/05/27/2060009.html 昨天看了一个教程,关于Linux命令的,本来以为当是复习随便 ...
- MVC-简单验证码制作
1.制作验证码: using System; using System.Collections.Generic; using System.Drawing; using System.Drawing. ...
- data structure online video
http://www.onlinevideolecture.com/computer-science/nptel-iit-delhi/data-structures-and-algorithms/?c ...
- activity的测试工程activiti-explorer使用
1. activiti-explorer默认使用h2数据库,第一步要修改db.properties的配置,如果使用其他数据库的话,务必放入驱动包,oracle的ojdbc4不能用,会报错,要使用版本高 ...
- ARM的NEON协处理器是什么
ARM的NEON协处理器是什么 何谓多媒体扩展指令集?由于原理复杂坚涩,小编就简单的打个比方:厂商们分析平时处理器干哪些事情最慢.又最经常用到,然后把这些最消耗时间的事情固化成电路,做成一个额外的部分 ...
- linux下跨服务器文件文件夹的复制
文件的复制:scp –P (端口号) ./authorized_keys berchina@hadoop002:/home/berchina 文件夹的复制:scp -r -P (端口号) /home/ ...
- C# zip压缩
/**//* * Gary Zhang -- cbcye@live.com * www.cbcye.com * www.quicklearn.cn * cbcye.cnblogs.com */ usi ...