# 洛谷CF809C Find a car（数位DP）

#include<bits/stdc++.h>
#define R register int
using namespace std;
const int YL=1e9+7;
int t,fc[8],fs[8],gc[8],gs[8];
inline int in(){R x;scanf("%d",&x);return x;}
inline void M(R&x){if(x>=YL)x-=YL;}
#define T(x,u,v) if(i>1||w==x)Trans(i>>1,li,u,v,i>1?w^x:w)
void Trans(R i,R li,R u,R v,R w){//暴搜转移
if(!i){
if(w)gs[v]=(gs[v]+fc[u]*(long long)t)%YL;
return M(gc[v]+=fc[u]),M(gs[v]+=fs[u]);
}
if(i&li){T(0,u,v|i);T(1,u,v);}//讨论开始
else T(0,u,v);
T(0,u|i,v|i);
T(1,u|i,v|i);
}
int Dp(R n,R m,R k){
if(n<0||m<0)return 0;
memset(fc,0,32);fc[0]=1;
memset(fs,0,32);
for(t=1<<30;t;t>>=1){
Trans(4,!!(n&t)*4|!!(m&t)*2|!!(k&t),0,0,0);
memcpy(fc,gc,32),memset(gc,0,32);
memcpy(fs,gs,32),memset(gs,0,32);
}
R s=0;
for(R i=0;i<8;++i)M(s+=fs[i]),M(s+=fc[i]);
return s;
}
int main(){
for(R q=in();q--;){
R x1=in()-2,y1=in()-2,x2=in()-1,y2=in()-1,k=in()-1;
cout<<((Dp(x2,y2,k)-Dp(x1,y2,k)-Dp(x2,y1,k)+Dp(x1,y1,k))%YL+YL)%YL<<endl;
}
return 0;
}

posted @ 2019-03-17 17:17  Flash_Hu  阅读(347)  评论(0编辑  收藏  举报