http://www.ifrog.cc/acm/problem/1049

这些数学题我一般都是找规律的。。

先暴力模拟了前面的那些,然后发现(x, y) = (x, y - 1) + (x - 1, y)得到。

但是这是没用的。因为要得到(x, y - 1)这些,又要递归处理的话,就会GG。

然后找到规律是C(x + y, y) - C(x + y, y - 1)

得闲没事就要多YY。。去试试X和Y中满足什么关系。

一般都一定要和这两个数有有关,和2 * x这些很少关系。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const LL MOD = 1e4 + ;
LL quick_pow (LL a,LL b,LL MOD) {
//求解 a^b%MOD的值
LL base=a%MOD;
LL ans=; //相乘,所以这里是1
while (b) {
if (b&) {
ans=(ans*base)%MOD; //如果这里是很大的数据,就要用quick_mul
}
base=(base*base)%MOD; //notice
//注意这里,每次的base是自己base倍
b>>=;
}
return ans;
} LL C (LL n,LL m,LL MOD) {
if (n<m) return ; //防止sb地在循环,在lucas的时候
if (n==m) return ;
LL ans1 = ;
LL ans2 = ;
LL mx=max(n-m,m); //这个也是必要的。能约就约最大的那个
LL mi=n-mx;
for (int i = ; i <= mi; ++i) {
ans1 = ans1*(mx+i)%MOD;
ans2 = ans2*i%MOD;
}
return (ans1*quick_pow(ans2,MOD-,MOD)%MOD); //这里放到最后进行,不然会很慢
}
LL Lucas (LL n,LL m,LL MOD) {
LL ans=;
while (n && m && ans) {
ans=ans*C(n%MOD,m%MOD,MOD)%MOD;
n /= MOD;
m /= MOD;
}
return ans;
}
LL calc(LL x, LL y) {
LL ans = (Lucas( * x, x, MOD) + MOD - Lucas( * x, x + , MOD)) % MOD;
return ans;
}
void work() {
LL x, y;
cin >> x >> y;
if (y == ) {
cout << << endl;
} else {
if (x == y) {
cout << calc(x, y) << endl;
} else {
cout << (Lucas(x + y, y, MOD) - Lucas(x + y, y - , MOD) + MOD) % MOD << endl;
}
}
}
int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
// for (x = 1; x <= 10; ++x) {
// for (y = 0; y <= x; ++y) {
// work();
// }
// cout << endl;
// }
IOS;
int t;
cin >> t;
while (t--) work(); return ;
}

最新文章

  1. Map的keySet和entrySet
  2. Cardinal样条曲线的Javascript实现(代码篇)
  3. checkbox与jq&lt;转&gt;
  4. 理解flex_对齐
  5. 一篇介绍jquery很好的
  6. AspectJ的简单使用
  7. centos 6 编译安装httpd-2.4
  8. EXT.NET常用属性
  9. 读书笔记-你不知道的JS中-函数生成器
  10. [JCIP笔记] (三)如何设计一个线程安全的对象
  11. MySQLSource-Flume
  12. iOS Core Data 数据库的加密(待研究)
  13. 589. N叉树的前序遍历
  14. 万网域名查询API接口
  15. 移动端热更新方案(iOS+Android)
  16. java 基础01
  17. git merge简介
  18. 关于git CRLF LF结尾的问题
  19. Smarty标签运算,控制结构[if,for,foreach,section,while]
  20. EditPlus 4.3.2543 中文版已经发布(2月3日更新,Emmet 功能回归)

热门文章

  1. servlet与jsp理论知识讲解
  2. the art of seo(chapter three)
  3. YCSB-mapkeeper
  4. 51nod最长递增路径:(还不错的图)
  5. 给YUI Compressor添加右键命令,完成快捷压缩
  6. cf 424
  7. 1.5 sqoop安装及基本使用
  8. js页面的全屏展示和退出全屏显示
  9. LeetCode: 520 Detect Capital(easy)
  10. npm和package.json那些不为常人所知的小秘密