CodeForces 305D Olya and Graph
来源:互联网 发布:淘宝基础店铺全屏店招 编辑:程序博客网 时间:2024/05/29 02:14
题目大意
给定一条单向链,上面有一些和链方向一致的边,每条边(包括加的)长度都是1,求有多少种方式加边可以使每一对
解答
由题目易知,所有边的长度必须是
如果并没有在链上的边,我们就可以在每一个长度为
如果有边,就相当于确定了区间的范围
我们只需要找到第一个可以连边的区间,这个区间的方案数应为
参考代码
#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <iostream>#include <vector>using namespace std;const int MOD = 1000000007;int n, m, k;vector<int> ser;int tw[1000005];int l, r;int main(){ tw[0] = 1; for (int i = 1; i < 1000005; i++) tw[i] = (tw[i-1] + tw[i-1]) % MOD; ios::sync_with_stdio(false); cin >> n >> m >> k; while (m--) { cin >> l >> r; if (r-l != 1 && r-l != k+1) { cout << "0"; return 0; } if (r-l == k+1) { ser.push_back(r); } } k++; if (ser.size() >= 2) { if (ser[ser.size()-1] - ser[0] >= k) { cout << "0"; return 0; } } if (k >= n) { cout << "1"; return 0; } int m = ser.size(); if (m == 0) { int ans = tw[min(n-k, k)]; for (int i = k+k+1; i <= n; i++) { ans += tw[k-1]; ans %= MOD; } cout << ans; return 0; } int ans = tw[min(n-k, k) - m]; for (int i = max(ser[m-1], 2*k) + 1; i <= n && i-ser[0] < k; i++) { ans += tw[k-1-m]; ans %= MOD; } cout << ans; return 0;}
0 0
- CodeForces 305D Olya and Graph
- Codeforces 877 D Olya and Energy Drinks
- Codeforces 877D Olya and Energy Drinks【思维优化Bfs】
- Codeforces 877 D. Olya and Energy Drinks (bfs)
- Codeforces Round #442 (Div. 2) D. Olya and Energy Drinks
- codeforces 877 problem D Olya and Energy Drinks 【bfs剪枝】
- Codeforces Round #877 (Div. 2) D. Olya and Energy Drinks
- [codeforces] 877D. Olya and Energy Drinks (BFS)
- Codeforces Round #442(Div.2)Problem D Olya and Energy Drinks(BFS)
- Codeforces Round #442 (Div. 2) 877 D. Olya and Energy Drinks BFS
- Codeforces 877D. Olya and Energy Drinks BFS+并查集
- Codeforces Round #442 (Div. 2) D. Olya and Energy Drinks (bfs)
- Codeforces Round #442 (Div. 2)-广搜&剪枝&技巧&好题-D. Olya and Energy Drinks
- cf 877D Olya and Energy Drinks
- CodeForces 366D Dima and Trap Graph
- CodeForces 387D George and Interesting Graph
- codeforces #442 div2 Olya and Energy Drinks
- Codeforces 296D/295B(Greg and Graph)
- jquery each跳出循环的问题
- 保角映射
- Cookie与Session
- Objective-C编码规范:26个方面解决iOS开发问题
- GSM系统消息
- CodeForces 305D Olya and Graph
- iOS攻略之动态添加tableView的行
- xml数据的解析
- Real Time Rendering --third edition 16.8节翻译
- iOS 获得版本号 区分BundleVersion和BundleShortVersionString
- 过滤器与拦截器区别,action通配符配置,struts2数据验证
- Codeforces Gym 100814C Connecting Graph (并查集, 树链剖分)
- LINUX+10.2.0.3 RAC删除、增加节点所遇问题记录
- 桥接模式