String

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2161    Accepted Submission(s): 628

Problem Description
Recently,
lxhgww received a task : to generate strings contain '0's and '1's
only, in which '0' appears exactly m times, '1' appears exactly n times.
Also, any prefix string of it must satisfy the situation that the
number of 1's can not be smaller than the number of 0's . But he can't
calculate the number of satisfied strings. Can you help him?
 
Input
T(T<=100) in the first line is the case number.
Each case contains two numbers n and m( 1 <= m <= n <= 1000000 ).
 
Output
Output the number of satisfied strings % 20100501.
 
Sample Input
1
2 2
 
Sample Output
2
 
Author
lxhgww
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  3400 3402 3401 3399 3404
 
转化成Cn+m n - Cn+m n+1
 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
const long long mod = ; bool s[];
int prime[],len;
void Init(){
int i,j;
memset(s,false,sizeof(s));
len=;
for(i=;i<=;i++)
{
if(s[i]==true) continue;
prime[++len]=i;
if(i>) return;
for(j=i*;j<=;j=j+i)
s[j]=true;
}
}
int get_num(int n,int m){
int ans=;
while(n){
n=n/m;
ans=ans+n;
}
return ans;
}
LL pow_mod(LL a,LL b)
{
LL ans=;
while(b)
{
if(b&){
ans=(ans*a)%mod;
}
b=b>>;
a=(a*a)%mod;
}
return ans;
} void solve(int n,int m){
int ans;
LL sum1=,sum2=;
for(int i=;i<=len;i++)
{
if(prime[i]>n+m)break;
ans=get_num(n+m,prime[i])-get_num(n,prime[i])-get_num(m,prime[i]);
sum1=(sum1*pow_mod(prime[i],ans))%mod; ans=get_num(n+m,prime[i])-get_num(n+,prime[i])-get_num(m-,prime[i]);
sum2=(sum2*pow_mod(prime[i],ans))%mod;
}
// printf("%lld %lld\n",sum1,sum2);
if(sum1<sum2) sum1=sum1-sum2+mod;
else sum1=sum1-sum2;
printf("%lld\n",sum1);
}
int main()
{
Init();
int T,n,m;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
solve(n,m);
}
return ;
}

hdu 3398的更多相关文章

  1. HDU 3398 String

    题目大意:一个长为n的01字符串,使前缀任意0的数量不大于1的数量,求方案数…… 题解:高一模拟赛时做过,是卡特兰数的几何意义,将字符串变为矩阵寻路,不可越过对角线,那么就是卡特兰数了,C(n+m, ...

  2. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  3. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. Error applying BeanValidation relational constraints 错误解决

    来自http://blog.csdn.net/sivyer123/article/details/9185325 在hibernate.hbm.xml中加上 <property name=&qu ...

  2. paper 10:支持向量机系列七:Kernel II —— 核方法的一些理论补充,关于 Reproducing Kernel Hilbert Space 和 Representer Theorem 的简介。

    在之前我们介绍了如何用 Kernel 方法来将线性 SVM 进行推广以使其能够处理非线性的情况,那里用到的方法就是通过一个非线性映射 ϕ(⋅) 将原始数据进行映射,使得原来的非线性问题在映射之后的空间 ...

  3. sql server 查看数据库编码格式

    user masterselect SERVERPROPERTY(N'edition') as Edition --数据版本,如企业版.开发版等,SERVERPROPERTY(N'collation' ...

  4. overfit & underfit

    原文:http://blog.csdn.net/yhdzw/article/details/22733317 过拟合:1)简单理解就是训练样本的得到的输出和期望输出基本一致,但是测试样本输出和测试样本 ...

  5. css在IE和Firefox下的兼容性

    1.div的垂直居中问题 vertical-align:middle,将行距增加到和整个div高度一样,加line-height:200px;然后插入文字就垂直居中了.缺点是要控制内容不要换行. 2. ...

  6. 典型的检查对float精度理解的代码

    -rand()%); vy = ); vz = ); pList_particle[i].m_velocity = Vector3(vx,vy,vz); ... 1,3行代码的vx和vz的值域可以通过 ...

  7. ASP.NET MVC API 路由生成规则

    我们都知道调用ASP.NET MVC的某些API函数(诸如:Url.Action.RedirectToAction等)可以生成URL,ASP.NET MVC会根据调用API函数时传入的参数去匹配系统定 ...

  8. MyEcplise中关于部署文件不成功的问题

    MyEclipse 点击 部署 按钮 无效   正常情况下,当我们点击MyEclipse任务栏上的部署按钮时,会弹出项目部署框,如下图:     但我们有时也会遇到点击部署按钮怎么也弹不出项目部署框的 ...

  9. iOS 学习笔记 十 (2015.04.03)xcode第三方插件

    1.xcode第三方插件,存放路径:~/Library/Application Support/Developer/Shared/Xcode/Plug-ins

  10. JS实现复制网页内容自动加入版权内容代码和原文链接

    JS实现复制网页内容自动加入版权内容代码和原文链接 实现代码:在body内放入如下代码即可: <script type="text/javascript"> var S ...