A word face
∑ x=0 n? 1 ∑ y = 0 m? 1 mIN(x⊙y ?k,0)(MoDP)
Okay, here's the face.
Just a bit of DP.
Memory words when the search is not really need a lot of classification discussion, the specific look at the code bar
#include <bits/stdc++.h>using namespace STD;#define LL Long LongConst intMAXN = -; LL N[MAXN],M[MAXN],K[MAXN]; LL p; LL cnt[maxn][2][2][2],dp[maxn][2][2][2]; LL TW[MAXN];voidBiter (LL x,ll *s) { for(inti =0; i<maxn;i++) {s[i] = x%2; X/=2; }}ll DFSN (intPosBOOLUnBOOLUmBOOLUK) {if(Pos <0)return 1; LL & ncnt = Cnt[pos][un][um][uk];if(Ncnt! =-1)returnncnt;intNB = un? N[pos]:1;intmb = um? M[pos]:1; ncnt =0; for(inti =0; i<=nb;i++) { for(intj=0; j<=mb;j++) {LL x = i ^ j;if(!uk | | x >= K[POS]) {ncnt + = DFSN (pos-1, un && i==nb,um && j = = Mb,uk && x==k[pos]); Ncnt%= p; } } }returnncnt;} LL DFS (intPosBOOLUnBOOLUmBOOLUK) {if(Pos <0)return 0; LL & NDP = Dp[pos][un][um][uk];if(NDP! =-1)returnNDPintNB = un? N[pos]:1;intmb = um? M[pos]:1; NDP =0; for(intI=0; i<=nb;i++) { for(intj=0; j<=mb;j++) {LL x = i ^ j;if(!uk | | x >= K[POS]) {LL mid = x; Mid *= DFSN (pos-1, un && i== nb,um && j = Mb,uk && X==k[pos]); (Mid *= Tw[pos])%= p; NDP + = Mid; (NDP + = DFS (pos-1, un && i== nb,um && j = Mb,uk && X==k[pos]))%= p; } } }returnNDP;} LL Cal (ll n,ll m,ll K) {tw[0] =1; for(intI=1; i<maxn;i++) {Tw[i] = (tw[i-1] *2)% P; } N--, m--; Biter (N,n); Biter (M,M); Biter (K,K);memset(dp,-1,sizeof(DP));memset(cnt,-1,sizeof(CNT)); LL Tim = DFSN (maxn-1,true,true,true); LL val = dfs (maxn-1,true,true,true); K%= p; Tim *= K% p; (Val-= Tim% P)%= p; val + = p; Val%= p;returnVal;}intMain () {intT LL n,m,k;Cin>>T; while(t--&&Cin>>N>>M>>K>>P) {cout<<cal (n,m,k) <<endl; }return 0;}
People weak wrote two times Dfs ...
Bzoj 4513 Energy Storage Meter