[数位DP] Codeforces 809C Round #415 (Div. 1) C. Find a car
来源:互联网 发布:java中的接口是什么 编辑:程序博客网 时间:2024/05/19 15:41
这个东西就是
然后转化为
这个东西 数位dp下就好了 代码常数略大 但是还是很好看的
#include<cstdio>#include<cstdlib>#include<algorithm>#include<cstring>#define cl(x) memset(x,0,sizeof(x))using namespace std;typedef long long ll;#define read(x) scanf("%d",&(x))const int P=1e9+7;ll sum[35][2][2][2],cnt[35][2][2][2];inline ll Calc(int _x,int _y,int _K){ if (_x==-1 || _y==-1) return 0; int x[35]={0},y[35]={0},K[35]={0},_p=0; _p=-1; while (_x) x[++_p]=_x&1,_x>>=1; _p=-1; while (_y) y[++_p]=_y&1,_y>>=1; _p=-1; while (_K) K[++_p]=_K&1,_K>>=1; cl(sum); cl(cnt); cnt[31][0][0][0]=1; for (int i=31;i;i--) for (int t1=0;t1<2;t1++) for (int t2=0;t2<2;t2++) for (int t3=0;t3<2;t3++){ for (int a=0;a<=(t1?1:x[i-1]);a++) for (int b=0;b<=(t2?1:y[i-1]);b++){ if ((a^b)>(t3?1:K[i-1])) continue; int nt1=t1|(a<x[i-1]),nt2=t2|(b<y[i-1]),nt3=t3|((a^b)<K[i-1]); (cnt[i-1][nt1][nt2][nt3]+=cnt[i][t1][t2][t3])%=P; (sum[i-1][nt1][nt2][nt3]+=sum[i][t1][t2][t3]+cnt[i][t1][t2][t3]*((a^b)<<(i-1))%P)%=P; } } ll Sum=0,Cnt=0; for (int t1=0;t1<2;t1++) for (int t2=0;t2<2;t2++) for (int t3=0;t3<2;t3++) (Sum+=sum[0][t1][t2][t3])%=P,(Cnt+=cnt[0][t1][t2][t3])%=P; return (Sum+Cnt)%P;}int main(){ int Q,x1,x2,y1,y2,K; freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(Q); while (Q--){ read(x1); read(y1); read(x2); read(y2); read(K); x1--; y1--; x2--; y2--; K--; printf("%I64d\n",(Calc(x2,y2,K)+P-Calc(x2,y1-1,K)+P-Calc(x1-1,y2,K)+Calc(x1-1,y1-1,K))%P); } return 0;}
阅读全文
0 0
- [数位DP] Codeforces 809C Round #415 (Div. 1) C. Find a car
- [数位DP] Codeforces 809C Round #415 (Div. 1) C. Find a car
- [数位DP] Codeforces 809C. Find a car
- [数位DP] Codeforces #809C. Find a car
- [数位DP AC自动机] Codeforces 434C Round #248 (Div. 1) C. Tachibana Kanade's Tofu
- Codeforces-809C Find a car(分治)
- 【dp】Codeforces Round #110 (Div. 1) C
- Codeforces Round #396 (Div. 2) A---C 暴力+dp
- Codeforces 809C [数位DP]
- Codeforces Round #369 (Div. 2) C. Coloring Trees 数位dp,好题
- Codeforces Round #230 (Div. 2) C / (Div. 1) A
- Codeforces Round #274 Div.1 C Riding in a Lift --DP
- Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend(贪心+DP)
- Codeforces Round #385 (Div. 1) C. Hongcow Buys a Deck of Cards(DP/模拟退火)
- 【DP】Codeforces Round #336 (Div. 2) C
- Codeforces Round #363 (Div. 2) C dp
- Codeforces Round #303 (Div. 2) C dp
- Codeforces Round #286 (Div. 2) C dp
- 打开虚拟机出现这种情况:获取 VirtualBox COM 对象失败,应用程序将被中断。
- 系统移植的四大步骤 详解
- java数据类型
- LeetCode 492. Construct the Rectangle (算法)
- 做题笔记
- [数位DP] Codeforces 809C Round #415 (Div. 1) C. Find a car
- KMS特好用的windows和office激活工具
- Android中架构X64与X32的不同
- SQL Server相同列只显示一条数据,不影响其他行数据
- python的一些东西
- ubuntu 14.04 server 依赖教育镜像服务器搭建本地镜像服务器
- 简单学习awk
- 排序-选择排序-数据结构(31)
- thymeleaf参考手册