HDU6044 Limited Permutation[快速输入][分治]
来源:互联网 发布:淘宝助手客服电话 编辑:程序博客网 时间:2024/06/07 06:47
题意:给定
题目提示输入使用快速的fread()
对于一个确定的区间
对于用到的组合数结果,使用卢卡斯预处理出结果。
#include<bits/stdc++.h>using namespace std;typedef long long LL;const int N = 1e6+10;const int mod = 1e9+7;int n;int l[N], r[N];map<pair<int ,int>, int> mp;LL ans;LL fac[N], inv[N];inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}template <class T>inline bool scan_d(T & x){ char c=nc(); x=0; if(c==EOF)return false; for(; c>'9'||c<'0'; c=nc()); for(; c>='0'&&c<='9'; x=x*10+c-'0',c=nc()); return true;}void init(){ fac[0]=1; for(int i = 1; i < N; i++) fac[i] = (fac[i-1]*i) % mod; inv[0] = inv[1] = 1; for(int i=2; i<N; i++) inv[i]=(LL)(mod-mod/i)*inv[mod%i]%mod; for(int i=1; i<N; i++) inv[i]=(inv[i-1]*inv[i])%mod;}LL C(int n,int m){ return fac[n]*inv[m]%mod*inv[n-m]%mod;}void dfs(int ll,int rr){ if(ans==0 || rr<ll) return; int i = mp[make_pair(ll, rr)]; if(i == 0) { ans=0; return; } if(ll == rr)return; int len = rr - ll; ans = (ans*C(len,i-ll)) % mod; dfs(ll, i-1); dfs(i+1, rr);}int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif // ONLINE_JUDGE init(); for(int Case = 1; scan_d(n); ++Case) { mp.clear(); for(int i = 1; i <= n; ++i) scan_d(l[i]); for(int i = 1; i <= n; ++i) { scan_d(r[i]); mp[make_pair(l[i], r[i])] = i; } ans = 1; dfs(1, n); printf("Case #%d: %I64d\n", Case, ans); } return 0;}
阅读全文
0 0
- HDU6044 Limited Permutation[快速输入][分治]
- hdu6044 Limited Permutation【读入优化+dfs】
- HDU6044 Limited Permutation (递归,预处理阶乘逆元)
- HDU6044-Limited Permutation(fread挂&&阶乘求逆元&&组合数)
- Limited Permutation HDU
- hdu 6044 Limited Permutation
- HUD 6044 Limited Permutation
- HDU 6044 Limited Permutation 想法
- HDU-6044 Limited Permutation(计数)
- HDU 6044 Limited Permutation dfs 统计
- HDU 6044 Limited Permutation(递归)
- HDU 6044 Limited Permutation dfs + 组合数(读入挂)
- 2017 多校训练第一场 HDU 6044 Limited Permutation
- HDU 6044 Limited Permutation (组合数+逆元)
- Limited
- An antiarithmetic permutation +uva+分治
- uva - 11129 - An antiarithmetic permutation(分治)
- 【分治】UVa 11129 An antiarithmetic permutation
- NYOJ18andNYOJ613
- 两种车往两个车站运人的java问题
- UI之UITableView和UITableViewCell
- OSI七层网络模型和Linux四层概念模型
- 确定两串乱序同构
- HDU6044 Limited Permutation[快速输入][分治]
- 利用数组显示杨辉三角
- 【国家集训队2011】数颜色 (莫队)
- 矩阵转换
- CTP Python API(利用Swig 封装)Windows版(mduserapi)
- JDK、Eclipse、Myeclipse、Tomcat等各种软件的版本详解(写给对版本和兼容性问题焦头烂额的你)
- 第一次Filter过滤器的简单使用总结(二)
- 深度学习系列教程
- java中的日期实用类的一些举例