bzoj1856: [Scoi2010]字符串

可以将模型抽象成在在一个n*m的的矩形上从(0, 0)走到(n, m)的方案数,并要求不能做过y = x + 1,这条直线

考虑任何一条不合法的路径,必然经过y = x + 1,考虑(0, 0)关于y = x + 1的对称点(-1, 1),每一条从(-1, 1)到(n, m)的路径都是经过支线y = x + 1的,并且可以通过翻折建立一一对应的关系,所以答案就是C(n + m, n) - C(n + m, n - 1)

 

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 #include<cstdlib>
 5 #include<cstring>
 6 #include<string>
 7 
 8 using namespace std;
 9 
10 void setIO(const string& a) {
11     freopen((a+".in").c_str(), "r", stdin);
12     freopen((a+".out").c_str(), "w", stdout);
13 }
14 
15 typedef long long LL;
16 const int Mod = 20100403;
17 
18 LL pow(LL a, LL b, LL p) {
19     for(LL res = 1; ; (a *= a) %= Mod) {
20         if(b & 1) (res *= a) %= Mod;
21         if(!(b >>= 1)) return res;
22     }
23 }
24 
25 int main() {
26     
27     LL n, m;
28     cin >> n >> m;
29     LL res = n + 1 - m;
30     for(int i = m + 1; i <= n + m; i++) {
31         (res *= i) %= Mod;
32     }
33     LL tmp = 1;
34     for(int i = 1; i <= n + 1; i++) {
35         (tmp *= i) %= Mod;
36     }
37     (res *= pow(tmp, Mod - 2, Mod)) %= Mod;
38     
39     cout << res << endl;
40     
41     return 0;
42 }

 

posted @ 2015-11-30 10:58  Showson  阅读(182)  评论(0编辑  收藏  举报