摘要: /* Lucas定理 C(n,m)%p(p为素数) C(n,m)与C(a[n],b[n])*C(a[n-1],b[n-1])*C(a[n-2],b[-2])*....*C(a[0],b[0])模p同余 a,b 是n,m在p进制下的数 有的推公式: (C(n%p,m%p,p)*Lcs(n/p,m/p,p))%p; 关键是求 C(n%p,m%p,p) 递归会很慢 for的话会爆掉 这里用一个定理:a... 阅读全文
posted @ 2016-05-21 17:23 一入OI深似海 阅读(228) 评论(0) 推荐(0) 编辑
摘要: /* 将n个不同的球放入m个不同的盒子的方案数 m^n */ #include #include #include using namespace std; int n,m,a[1010],l; int main() { scanf("%d%d",&n,&m); int k=m; while(k) { a[++l]=k%10; ... 阅读全文
posted @ 2016-05-21 16:05 一入OI深似海 阅读(358) 评论(9) 推荐(0) 编辑
摘要: /* 暴力做法 : 从2开始枚举,然后暴力判断g^(P-1) = 1 (mod P)是否当且仅当指数为P-1的时候成立 25分0.0 */ #include #include #include #include using namespace std; long long Mi(int a,int m,int p) { if(m==0)return 1; long long x... 阅读全文
posted @ 2016-05-18 20:46 一入OI深似海 阅读(368) 评论(0) 推荐(1) 编辑
摘要: /* 扩展欧几里得 ax%b==1 -> ax-by==1 求不定方程的一组解 使x为最小正整数解 */ #include #include #include using namespace std; int x,y,gcd; int Extend(int a,int b) { if(b==0) { x=1;y=0; gcd=a... 阅读全文
posted @ 2016-05-17 19:58 一入OI深似海 阅读(227) 评论(0) 推荐(0) 编辑
摘要: #include #include #include #define maxn 30010 using namespace std; int n,m,num; struct node { int l,r,lc,rc,sum,fa;//sum是还有几个没出队的 }t[maxn*2+1000]; void Build(int ll,int rr) { int k=++num; ... 阅读全文
posted @ 2016-05-17 10:30 一入OI深似海 阅读(222) 评论(0) 推荐(0) 编辑
摘要: /* 做的不多的位数dp 暴力的话 不知道多少组数据 会T 所以写dp 思路就和数学课本上那种“不超过xxx的x位偶数有几个” 这里可以类似的维护一个前缀和模样的东西(但又不同于前缀和) 状态:f[i][j] 表示以j开头的i位数符合条件的个数 (j可以是0) 然后可以已处理一下像是10000这种整的数 注意舍去不符合条件的 然后对于一个像123456这样不整的数 就从该高位逐位找 以此类推... 阅读全文
posted @ 2016-05-16 18:15 一入OI深似海 阅读(225) 评论(0) 推荐(0) 编辑
摘要: #include #include #include #define maxn 100010 using namespace std; int n,m,num,a[maxn],tmp[maxn]; char s[100]; struct node { int l,r; int lc,rc; int s[7],bj; }t[maxn*2+100]; int init() {... 阅读全文
posted @ 2016-05-16 16:07 一入OI深似海 阅读(184) 评论(0) 推荐(0) 编辑
摘要: /* dp 如果是统计最少加多少个括号 就是区间dp 如果区间两头是匹配的 就可以用 i+1 j-1 更新 然而这题要输出方案 就类似记路径 记背包选哪几个一样 维护一个bj表示 i到j的最优解是由 分成哪两份转移来的 如果无法分 就是-1 最后递归搞输出方案 递归终点就是需要改变的点 */ #include #include #include using names... 阅读全文
posted @ 2016-05-15 18:29 一入OI深似海 阅读(139) 评论(0) 推荐(0) 编辑
摘要: /* Tarjan缩点之后 强联通分量建图 统计每个强联通分量的出入度 第一问就是入度为0的 强联通分量的个数 第二问 为了高效的使每个强联通分量都有出入度 要把出度为零的强联通分量连到入度为零的点上 这样得到的边数是最少的 ans2并不是桥的数目 这样不是最少..... */ #include #include #include #define maxn 110 #define maxm ... 阅读全文
posted @ 2016-05-15 08:58 一入OI深似海 阅读(161) 评论(0) 推荐(0) 编辑
摘要: #include #include #include using namespace std; int n,m,son[310][2],f[310][310],v[310],ans,falg; int init() { int x=0;char s;s=getchar(); while(s'9')s=getchar(); while(s>='0'&&sf[p][x])f[... 阅读全文
posted @ 2016-05-13 22:23 一入OI深似海 阅读(258) 评论(0) 推荐(0) 编辑