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. How to create a project with existing folder of files in Visual Studio?

    1. Select Visual Studio tool bar-> New -> Project from existing code-> continue with config ...

  2. [转] java编程规范

    原文链接: 资料推荐--Google Java编码规范 之前已经推荐过Google的Java编码规范英文版了: http://google-styleguide.googlecode.com/svn/ ...

  3. 封装pdo单例模式类

    <?php /** * MyPDO * @author Jason.Wei <jasonwei06@hotmail.com> * @license http://www.sunblo ...

  4. android fragment+ FragmentTabHost+viewpager 切换状态不保存的问题

    转载请注明出处:http://blog.csdn.net/djy1992/article/details/46674169 @author dujinyang 难得有时间上来写博客. fragment ...

  5. mongodb的js操作

    在包含url的test库中运行test.js mongo url:port/test test.js

  6. microsoft .netframework Available Source Code Components

    http://referencesource.microsoft.com/netframework.aspx http://blogs.msdn.com/b/dotnet/archive/2012/0 ...

  7. 什么是商业智能BI和实施BI的解决方案【转】

    商业智能,或BI,是一种统称,泛指用于对一个企业的原始数据进行分析的各种各样的软件系统.商业智能(BI)是由若干相关的活动组成的领域,包括数据挖掘,在线分析处理,查询和报表. 企业用商业智能(BI)来 ...

  8. Android webview实现上传图片的效果(图片压缩)

    mainactivity代码 package com.bwie.webviewupload; import java.io.ByteArrayInputStream; import java.io.B ...

  9. /etc/passwd /etc/shadow

    一./etc/passwd/etc/passwd 文件是一个纯文本文件,每行采用了相同的格式: name:password:uid:gid:comment:home:shell name 用户登录名  ...

  10. stc89c52开发板遥控器解码 红外线发射 内置 eeprom 存储 串口显示编码

    单片机,大概三年前,就买了一本 <爱上单片机> 最后就学会,用面包板了,编程书上基本没讲. 看原理图,看时序图,看数据手册, 都没讲. 而且书上自带的代码写的很烂. 1,缩近控制不好 2, ...