BZOJ3907
来源:互联网 发布:windows找不到runtime 编辑:程序博客网 时间:2024/05/23 15:57
题解是粘的 代码也是粘的
转自这里
(0,0)->(n,m)方案数为C(n,n+m), 然后减去不合法的方案. 作(n,m)关于y=x+1的对称点(m-1,n+1), 则(0,0)->(m-1,n+1)的任意一条路径都对应(0,0)->(n,m)的一条不合法路径(y>x). 所以答案就是C(n,n+m) - C(n+1,n+m).高精度算就OK了
#include<cstring>#include<algorithm>using namespace std;const int maxn = 10009;const int maxpn = 1500;int N, M;int p[maxpn], pn = 0;int a[2][maxpn];bool check[maxn];void init() { scanf("%d%d", &N, &M); memset(check, 0, sizeof check); for(int i = 2, lim = N + M; i <= lim; i++) { if(!check[i]) p[pn++] = i; for(int j = 0; j < pn && i * p[j] <= lim; j++) { check[i * p[j]] = true; if(i % p[j] == 0) break; } } memset(a, 0, sizeof a); for(int i = N + 2; i <= N + M; i++) for(int j = 0, t = i; j < pn && t >= p[j]; j++) for(; t % p[j] == 0; a[0][j]++, a[1][j]++, t /= p[j]); for(int t = N + 1, j = 0; j < pn && t >= p[j]; j++) for(; t % p[j] == 0; a[0][j]++, t /= p[j]); for(int i = 2; i < M; i++) for(int j = 0, t = i; j < pn && t >= p[j]; j++) for(; t % p[j] == 0; a[0][j]--, a[1][j]--, t /= p[j]); for(int t = M, j = 0; j < pn && t >= p[j]; j++) for(; t % p[j] == 0; a[0][j]--, t /= p[j]);}struct Int { static const int base = 10000; static const int maxn = 1000; static const int width = 4; int s[maxn], n; Int() : n(0) { memset(s, 0, sizeof s); } Int operator = (int num) { n = 0; for(; num; num /= base) s[n++] = num % base; return *this; } Int(int x) { *this = x; } Int operator = (const Int &o) { n = o.n; memcpy(s, o.s, sizeof(int) * n); return *this; } void write() { int buf[width]; for(int i = n; i--; ) { int t = s[i], c = 0; for(; t; t /= 10) buf[c++] = t % 10; if(i + 1 != n) for(int j = width - c; j; j--) putchar('0'); while(c--) putchar(buf[c] + '0'); } puts(""); } Int operator + (const Int &o) const { Int res; for(int i = 0, g = 0; ; i++) { if(!g && i >= o.n && i >= n) break; int x = g + (i < n ? s[n] : 0) + (i < o.n ? o.s[o.n] : 0); res.s[res.n++] += x / base; g = x % base; } return res; } Int operator += (const Int &o) { return (*this = *this + o); } Int operator * (const Int &o) const { Int ret; ret.n = o.n + n - 1; for(int i = 0; i < n; i++) for(int j = 0; j < o.n; j++) { int t = s[i] * o.s[j]; ret.s[i + j] += t % base; ret.s[i + j + 1] += t / base; } for(int i = 0; i < ret.n; i++) if(ret.s[i] >= base) { ret.s[i + 1] += ret.s[i] / base; ret.s[i] %= base; } for(int &i = ret.n; ret.s[i]; i++) { ret.s[i + 1] += ret.s[i] / base; ret.s[i] %= base; } return ret; } Int operator *= (const Int &o) { return (*this = *this * o); } Int operator - (const Int &o) const { Int ret = *this; for(int i = ret.n; --i; ) { ret.s[i]--; ret.s[i - 1] += base; } for(int i = 0; i < o.n; i++) if((ret.s[i] -= o.s[i]) >= base) ret.s[i + 1]++, ret.s[i] -= base; if(!ret.s[n - 1]) ret.n--; return ret; }};Int power(int p, int a) { Int ret = 1, _p = p; for(; a; _p *= _p, a >>= 1) if(a & 1) ret *= _p; return ret;}int main() { init(); Int ans = 1, t = 1; for(int i = 0; i < pn; i++) ans *= power(p[i], a[0][i]), t *= power(p[i], a[1][i]); (ans - t).write(); return 0;}
阅读全文
0 0
- BZOJ3907
- bzoj3907: 网格
- 网格[bzoj3907]
- BZOJ3907 网格
- 【BZOJ3907】网格 组合数,补集转换
- 高精+卡特兰数 bzoj3907网格
- [BZOJ3907]网格(卡特兰数+组合数学+高精度)
- JS入门(2)
- mescroll下拉刷新
- 在UBUNTU系统上安装OPENCV
- java.lang.IllegalStateException: Failed to find class [org.junit.runners.model.MultipleFailureExcep
- Oracle flashback 闪回 笔记
- BZOJ3907
- github 上传图片到项目中一直失败:现象(commit files按钮不能按)
- Spring Cloud Config环境库
- ionic的用法和作用
- Oracle 查看表空间的大小及使用情况sql语句
- Android 沉浸式状态栏的三种实现方式
- 首页 » Android开发环境 » 解决安装使用SDK Manager更新时的问题:Failed to fetch URL... 解决安装使用SDK Manager更新时的问题:Failed to
- Hadoop MapReduce执行过程详解(带hadoop例子)
- 真正聪明的人从来不自己做PPT,看完这篇就放假吧!