摘要: 唯一分解定理。 可以看出在最后每个a的系数是杨辉三角的第n行。 但是不能递推,否则会tle。 就从C(n-1,0)开始乘n-k再除以k。记录下每个的系数,如果该项系数小于m就代表和答案有关。 代码里的ok为true时,代表和答案有关。 #include #include #include #include using namespace std; const int maxn = ... 阅读全文
posted @ 2016-06-10 23:51 invoid 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 二分图最小权完美匹配。 一个最小费用流就能跑了,记住检查一下,容量是否跑满,如果没有跑满,就说明没有完美匹配。 #include #include #include using namespace std; const int maxn = 500+10; const int maxm = 50000 + 10; const int inf = 0x3f3f3f3f; int g[ma... 阅读全文
posted @ 2016-06-10 20:35 invoid 阅读(128) 评论(0) 推荐(0) 编辑
摘要: dp. 首先我们可以看到每个时间段只能往一个方向转移最多t步(t为时间段的长度),所以我们可以按时间段dp。因为这个前后值互不影响,也不用占用这一维空间就可以省去。 然后每个时间段内是一列一列(行) 进行递推。 如果朴素枚举是O(n^2)时间无法承受。所以每列(行)用一个单调队列维护dp,队首放着移动距离最大可以到达的点,这样复杂度就降到了O(n)。每次要递推n列(行)。所以总复杂度为O(k*... 阅读全文
posted @ 2016-06-10 18:47 invoid 阅读(712) 评论(0) 推荐(2) 编辑
摘要: 筛法,打表。 通过打表可知,但gcd(a,b)==a xor b时,a xor b = a-b. 就是求满足 c = a-b且c = a xor b 的c的个数。 #include #include #include using namespace std; const int maxn = 30000000; int ans[maxn+10]; int a,b,c,n; int T... 阅读全文
posted @ 2016-06-10 15:47 invoid 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 唯一分解定理。 挨个记录下每个质数的指数。 #include #include #include #include using namespace std; const int maxn = 100000 + 10; typedef long long LL; double ans; int p,q,s,t; bool mark[maxn]; int prime[maxn],cnt; ... 阅读全文
posted @ 2016-06-10 13:17 invoid 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 快速幂, 循环节,斐波那契数列 只是一个水水的题目,可以看出循环节是小于n^2的,所以先枚举出循环节。然后快速幂取模就可以了。 但要注意必须用unsigned long long,而且我用scanf读入还出现了意想不到的问题,所以只能用cin读入。 这是一个很大的坑点. #include #include #include using namespace std; const int... 阅读全文
posted @ 2016-06-10 10:31 invoid 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 扩展欧几里得。 枚举a,根据x1,x3和递推式可得。 (a+1)*b-k*mod=f[3]-a*a*b. 通过扩展欧几里得求出b. 带入原式进行计算。 #include #include #include using namespace std; const int maxn = 20000 + 10; const int mod = 10001; typedef long lo... 阅读全文
posted @ 2016-06-10 09:55 invoid 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 费用流。 裸的拆点最小费用流,一跑就行。 核弹预警,为何wa20多发。build函数一定要返回true。。。。。。 太可怕了 #include #include #include #include using namespace std; const int maxn = 5000 + 10 ; const int maxm = 200000 + 10; const int inf ... 阅读全文
posted @ 2016-06-10 08:52 invoid 阅读(114) 评论(0) 推荐(0) 编辑