标签:ecif include ted arm art file note ips ==
size_t fread(void *buffer, size_t size, size_t count, FILE *stream); // reads an array of count elements, each one with a size of size bytes, from the stream and stores them in the block of memory specified by buffer; the total number of elements successfully read is returned.
题解:
看懂题意
每个pi掌管 L ,R,题意是指超过这段范围就有比pi还要小的值
所有必然有一个pi 值掌管 1,n的,推出 必有 pj,pk分别 掌管 (1,i - 1), (i+1,n)
dfs下去计算方案
还有就是必须用读入挂才能过
#include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define ls i<<1 #define rs ls | 1 #define mid ((ll+rr)>>1) #define pii pair<int,int> #define MP make_pair typedef long long LL; typedef unsigned long long ULL; const long long INF = 1e18+1LL; const double pi = acos(-1.0); const int N = 1e6+10, M = 1e3+20,inf = 2e9,mod = 1e9 + 7; namespace IO { const int MX = 4e7; //1e7占用内存11000kb char buf[MX]; int c, sz; void begin() { c = 0; sz = fread(buf, 1, MX, stdin); } inline bool read(int &t) { while(c < sz && buf[c] != ‘-‘ && (buf[c] < ‘0‘ || buf[c] > ‘9‘)) c++; if(c >= sz) return false; bool flag = 0; if(buf[c] == ‘-‘) flag = 1, c++; for(t = 0; c < sz && ‘0‘ <= buf[c] && buf[c] <= ‘9‘; c++) t = t * 10 + buf[c] - ‘0‘; if(flag) t = -t; return true; } } const int MOD = (int)1e9 + 7; int F[N], Finv[N], inv[N];//F是阶乘,Finv是逆元的阶乘 void init(){ inv[1] = 1; for(int i = 2; i < N; i ++){ inv[i] = (MOD - MOD / i) * 1ll * inv[MOD % i] % MOD; } F[0] = Finv[0] = 1; for(int i = 1; i < N; i ++){ F[i] = F[i-1] * 1ll * i % MOD; Finv[i] = Finv[i-1] * 1ll * inv[i] % MOD; } } inline LL C(int n, int m){//comb(n, m)就是C(n, m) if(m < 0 || m > n) return 0; return F[n] * 1ll * Finv[n - m] % MOD * Finv[m] % MOD; } struct ss{ int l,r,id; bool operator<(const ss& x) const{ if(l == x.l) return r > x.r; else return l < x.l; } }a[N]; int now,ok; inline LL dfs(int ll,int rr) { if(!ok) return 0; if(ll > rr) return 1LL; if(a[now].l != ll || a[now].r != rr) { ok = 0; return 0; } int ids = a[now++].id; return dfs(ll,ids-1) * dfs(ids+1,rr) % mod * C(rr-ll,ids-ll) % mod; } int main() { init(); int cas = 1,n; IO::begin(); while(IO::read(n)) { for(int i = 1; i <= n; ++i) IO::read(a[i].l); for(int i = 1; i <= n; ++i) IO::read(a[i].r),a[i].id = i; now = 1, ok = 1; sort(a+1,a+n+1); printf("Case #%d: %lld\n",cas++,dfs(1,n)); } return 0; }
HDU 6044 Limited Permutation 读入挂+组合数学
标签:ecif include ted arm art file note ips ==
原文地址:http://www.cnblogs.com/zxhl/p/7289617.html