FJOI泛做
作者:互联网
教练找了点 \(FJOI\) 真题,准备做一下找点感觉,应该到 \(28\) 都会进行 \(FJOI\) 泛做。
后面几天要写一些知识复习和板子了。
FJOI2017 矩阵填数
一个简单的签到题,不过可能有些细节。考场可能写 \(1h\) 左右。
考虑按给定矩形边框划分整体,然后按 \([l,r],[u,d],v\) 五维量规定一个矩形块。
把给定的 \(l,r\),\(u,d\)排序后,每次取 \([l_i,l_{i + 1} - 1],[u_j,u_{j + 1} - 1]\) 即可。
注意每个条件矩形的最右边一列单独做。
\(O(2^nn^2)\)
点击查看代码
#include<bits/stdc++.h>
#define ll long long
#define N 15
int T;
struct P{int l,r,u,d,v;};//一个矩形
P A[N];
int h,w,m,n;
using std::vector;
vector<int>H,L;
#define mod (int)(1e9 + 7)
ll f[2][(1 << 15)];
inline bool in(P A,P B){return (B.l <= A.l && A.r <= B.r && B.u <= A.u && A.d <= B.d);}//A \in B ?
inline ll qpow(ll a,ll b){
ll res = 1;
while(b){
if(b & 1)res = res * a % mod;
a = a * a % mod;b >>= 1;
}
return res;
}
inline void print(int S){for(int i = 1;i <= n;++i)std::cout<<((S >> (i - 1)) & 1)<<" ";}
inline void del(int op,P W){
ll S = 0;
for(int i = 1;i <= n;++i)if(in(W,A[i])){if(A[i].v < W.v)W.v = A[i].v,S = 0;if(W.v == A[i].v)S |= (1ll << (i - 1));}
ll now;ll s = (W.r - W.l + 1) * (W.d - W.u + 1);
for(int i = 0;i < (1ll << n);++i)f[op][i] = 0;
//TO DO MAX
now = (qpow(W.v,s) - qpow(W.v - 1,s) + mod) % mod;
for(int i = 0;i < (1ll << n);++i)f[op][i | S] = (f[op ^ 1][i] * now % mod + f[op][i | S]) % mod;
//NO MAX
now = qpow(W.v - 1,s);
for(int i = 0;i < (1ll << n);++i)f[op][i] = (f[op ^ 1][i] * now % mod + f[op][i]) % mod;
}
int main(){
// freopen("grid.in","r",stdin);
// freopen("grid.out","w",stdout);
scanf("%d",&T);
while(T -- ){
scanf("%d%d%d%d",&h,&w,&m,&n);
H.clear(),L.clear();
H.push_back(1),H.push_back(h);
L.push_back(1),L.push_back(w);
for(int i = 1;i <= n;++i){
scanf("%d%d%d%d%d",&A[i].l,&A[i].u,&A[i].r,&A[i].d,&A[i].v);
H.push_back(A[i].l),H.push_back(A[i].r);
H.push_back(A[i].r + 1),L.push_back(A[i].d + 1);
L.push_back(A[i].u),L.push_back(A[i].d);
}
std::sort(H.begin(),H.end()),std::sort(L.begin(),L.end());
H.erase(std::unique(H.begin(),H.end()),H.end()),L.erase(std::unique(L.begin(),L.end()),L.end());
H.push_back(h + 1),L.push_back(w + 1);
int cnt = 1;
for(int i = 0;i < (1ll << n);++i)f[0][i] = 0;f[0][0] = 1;
for(int i = 0;i < H.size() - 1;++i)
for(int j = 0;j < L.size() - 1;++j){
P now;now.l = H[i],now.r = H[i + 1] - 1,now.u = L[j],now.d = L[j + 1] - 1;now.v = m;
del(cnt,now);
cnt ^= 1;
}
std::cout<<f[cnt ^ 1][(1ll << n) - 1]<<"\n";
}
}
标签:int,ll,long,FJOI,矩形,define 来源: https://www.cnblogs.com/dixiao/p/16190988.html