题目大意:一个长为n的01字符串,使前缀任意0的数量不大于1的数量,求方案数……

题解:高一模拟赛时做过,是卡特兰数的几何意义,将字符串变为矩阵寻路,不可越过对角线,那么就是卡特兰数了,C(n+m, n)-C(n+m,n+1)=(n+1-m)(n+m)!/(n+1)!m!。需要注意的是取模的问题,如果用高精度最后取模会太慢了,会超时,所以直接用power定理分解素数,对于每个素数分别算幂,取模相乘即可。

#include <cstdio>
#include <cstring>
const int N=1000001;
using namespace std;
typedef long long LL;
int pri[N*2+1],p[N*2+1],tot;
int cal(int pr,int n){int rs=0;while(n)n/=pr,rs+=n;return rs;}
void initp(){
memset(pri,0,sizeof pri); tot=0;
for(int i=2;i<=N*2;i++){
if(pri[i])continue; p[tot++]=i;
for(int j=i*2;j<=N*2;j+=i)pri[j]=1;
}
}
int main(){
int cas,n,m; initp();
scanf("%d",&cas);
while(cas--){
scanf("%d%d",&n,&m);
LL rs=1; int nm=n-m+1;
for(int i=0;i<tot&&p[i]<=n+m;i++){
int cnt=0;
while(nm%p[i]==0)nm/=p[i],cnt++;
int ipow=cnt+cal(p[i],n+m)-cal(p[i],n+1)-cal(p[i],m);
for(int j=1;j<=ipow;j++){
rs=(rs*p[i])%20100501;
}
}
printf("%lld\n",rs);
}
return 0;
}

HDU 3398 String的更多相关文章

  1. HDU 3374 String Problem (KMP+最大最小表示)

    HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  2. HDU 3374 String Problem(KMP+最大/最小表示)

    String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  3. hdu 5772 String problem 最大权闭合子图

    String problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5772 Description This is a simple pro ...

  4. HDU 4821 String(2013长春现场赛I题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4821 字符串题. 现场使用字符串HASH乱搞的. 枚举开头! #include <stdio.h ...

  5. HDU 2476 String painter(区间DP+思维)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2476 题目大意:给你字符串A.B,每次操作可以将一段区间刷成任意字符,问最少需要几次操作可以使得字符串 ...

  6. 2017多校第6场 HDU 6096 String AC自动机

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6096 题意:给了一些模式串,然后再给出一些文本串的不想交的前后缀,问文本串在模式串的出现次数. 解法: ...

  7. HDU 6194 string string string(后缀数组+RMQ)

    string string string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. HDU 482 String

    String Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 482 ...

  9. hdu 2476 String Painter

    第一道区间dp题,感觉题意不是很好理解 题意:一次可以转换某一个位置的字符,或是一串连续的字符,举第一个例子zzzzzfzzzzz 1:aaaaaaaaaaa 2: abbbbbbbbba 3: ab ...

随机推荐

  1. IBM HeapAnalyzer

    https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/W3b463571efc8_4f02_99af_3cbc0 ...

  2. HDU 3507 Print Article(CDQ分治+分治DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3507 [题目大意] 将长度为n的数列分段,最小化每段和的平方和. [题解] 根据题目很容易得到dp ...

  3. orcale装完sqldevelop启动不了

    一直在搞考试,昨天考java企业级开发要交项目搞得我装系统后又装了个orcale,每次重新配百度太麻烦,还好记得点,记录下碰到的错误 64位的系统下的orcale11 64位里面的sqldevelop ...

  4. qt4.8.4安装以及64位程序编译方法

    本文将使用简单的几个步骤说明在vc2008和64位的操作系统下如何编译安装x64Qt软件 首先必须保证你所使用的系统是64bit的操作系统,本次我们使用的系统是windows7 professiona ...

  5. HTML5新特性之CSS+HTML5实例

    1.新的DOCTYPE和字符集 HTML5的一项准则就是化繁为简,Web页面的DOCTYPE被极大的简化. <!DOCTYPE html> 同时字符集声明也被简化了: <meta c ...

  6. getDeclaredConstructor()与getConstructor的差别

    首先看getDeclaredConstructor(Class<?>... parameterTypes)  这种方法会返回制定參数类型的全部构造器,包含public的和非public的, ...

  7. php 求水仙花数优化

    水仙花数是指一个n位数(n>=3),它每一个位上数字的n次幂之和等于它本身,n为它的位数.(比如:1^3+5^3+3^3 = 153) 水仙花数又称阿姆斯特朗数. 三位的水仙花数有4个:153, ...

  8. hdu 4105 贪心思想

    淋漓尽致的贪心思想 波谷一定是一位数.波峰一位数不够大的时候加入到两位数就一定够大了的. 当在寻找波谷碰到零了就自然当成波谷. 当在寻找波峰时碰到零时,将前面的波谷加到前一个波峰上.让当前的零做波谷, ...

  9. NHibernate初入门之配置文件属性说明(四)

    一.NHibernate配置所支持的属性 属性名 用途 dialect 设置NHibernate的Dialect类名 - 允许NHibernate针对特定的关系数据库生成优化的SQL 可用值: ful ...

  10. Error (0xc0000225) installing Windows 8 R2 on VirtualBox

    Windows Boot Manager Windows failed to start. A recent hardware or software change might be the caus ...