https://www.luogu.org/problemnew/show/CF809C

这个题的难点主要在于看出这个矩阵所有数字-1后,第i行第j列就等于i^j。

这个规律对着这个表,观察一会大概是可以观察出来的。

然后就是容斥+数位dp求解即可。

#include<bits/stdc++.h>
#define N 1100
#define eps 1e-7
#define inf 1e9+7
#define db double
#define ll long long
#define ldb long double
using namespace std;
inline int read()
{char ch=0;int x=0,flag=1;while(!isdigit(ch)){ch=getchar();if(ch=='-')flag=-1;}while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}return x*flag;
}
const int mo=1e9+7;
void add(int &x,int k){x=(x+k)%mo;}
int f[N],g[N],h[N],dp[2][2][2],DP[2][2][2],dp_[2][2][2],DP_[2][2][2];
int solve()
{memset(dp,0,sizeof(dp));memset(DP,0,sizeof(DP));memset(dp_,0,sizeof(dp_));memset(DP_,0,sizeof(DP_));dp[0][0][0]=1;DP[0][0][0]=0;for(int i=1;i<=31;i++){int w=(1<<(30-i+1))%mo; for(int a=0;a<=1;a++)for(int b=0;b<=1;b++)for(int c=0;c<=1;c++)if(dp[a][b][c]||DP[a][b][c])for(int x=0;x<=(a?1:f[i]);x++)for(int y=0;y<=(b?1:g[i]);y++)if((x^y)<=(c?1:h[i])){int o=dp[a][b][c],t=DP[a][b][c];add(dp_[a|(x<f[i])][b|(y<g[i])][c|((x^y)<h[i])],o);add(DP_[a|(x<f[i])][b|(y<g[i])][c|((x^y)<h[i])],((1ll*(x^y)*o*w%mo)+t)%mo);}for(int a=0;a<=1;a++)for(int b=0;b<=1;b++)for(int c=0;c<=1;c++){dp[a][b][c]=dp_[a][b][c];dp_[a][b][c]=0;DP[a][b][c]=DP_[a][b][c];DP_[a][b][c]=0;}}int ans=0;for(int a=0;a<=1;a++)for(int b=0;b<=1;b++)for(int c=0;c<=1;c++)ans=(ans+((dp[a][b][c]+DP[a][b][c])%mo))%mo;return (ans%mo+mo)%mo;
}
void work()
{int a=read()-1,b=read()-1,c=read()-1,d=read()-1,k=read()-1,ans=0;for(int i=30;i>=0;i--)h[30-i+1]=((1<<i)&(k))?1:0;if(c>=0&&d>=0){for(int i=30;i>=0;i--)f[30-i+1]=((1<<i)&(c))?1:0;for(int i=30;i>=0;i--)g[30-i+1]=((1<<i)&(d))?1:0;ans=(ans+solve())%mo;}if(a-1>=0&&d>=0){for(int i=30;i>=0;i--)f[30-i+1]=((1<<i)&(a-1))?1:0;for(int i=30;i>=0;i--)g[30-i+1]=((1<<i)&(d))?1:0;ans=(ans-solve())%mo;}if(c>=0&&b-1>=0){for(int i=30;i>=0;i--)f[30-i+1]=((1<<i)&(c))?1:0;for(int i=30;i>=0;i--)g[30-i+1]=((1<<i)&(b-1))?1:0;ans=(ans-solve())%mo;}   if(a-1>=0&&b-1>=0){for(int i=30;i>=0;i--)f[30-i+1]=((1<<i)&(a-1))?1:0;for(int i=30;i>=0;i--)g[30-i+1]=((1<<i)&(b-1))?1:0;ans=(ans+solve())%mo;}printf("%d\n",(ans%mo+mo)%mo);
}
int main()
{int t=read();for(int i=1;i<=t;i++)work();return 0;
}

转载于:https://www.cnblogs.com/Creed-qwq/p/10801731.html

CF809C Find a car相关推荐

  1. CF809C(找规律+数位DP)

    老年选手需要多写一些思维题qwq. 通过打表很容易发现对于(i,j),值为(i-1)^(j-1)+1,然后本题就没了qwq. 矩阵差分还是很容易想到的,容斥成四个矩阵. 然后看到异或很容易想到三件事: ...

最新文章

  1. Android视图重绘,使用invalidate还是requestLayout
  2. PHP 根据类名和方法名已面向对象的方式执行函数。
  3. texlive环境运行WinEdt系统找不到指定的文件
  4. leetcode算法题--删除排序链表中的重复元素 II
  5. Hud 敌兵布阵 --线段树的插点问线
  6. logrotate测试_使用 logrotate 对 apache/nginx 日志切割
  7. facebook 面试_如何为您的Facebook产品设计面试做准备
  8. 解决:com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused:
  9. MySQL模糊查询的那些谣言
  10. python 矩阵除法_Python线性代数学习笔记——矩阵的基本运算和基本性质,实现矩阵的基本运算...
  11. 真香 自从用了Charles,Fiddler已经被我彻底卸载了
  12. CodeForces 828C String Reconstruction(并查集思想)
  13. MySQL innoDB数据插入性能优化
  14. jquery遍历的radio的取值问题
  15. 计算机专业建设会议纪要,本学期第六次专业建设工作会议纪要
  16. win10 更新后指纹不能使用
  17. 筛选N以内的素数C语言版(1022)
  18. arduino下载库出错_纯干货!关于Arduino 库在多种操作系统安装使用最详细、最全面的指南及常见问题解决办法!...
  19. hone hone clock创意前端时钟
  20. 文件管理(文件系统)

热门文章

  1. Struts2标签 逻辑标签和UI标签
  2. POJ-2942:吃糖果
  3. Linux新建yaml文件,yaml文件创建pod和deployment
  4. vs linux 交叉编译,Visual Studio交叉编译器提供对ARM的支持
  5. mybatis 依赖于jdbc_Mybatis和JDBC区别
  6. amd显卡风扇调节_和AMD首席游戏架构师Frank Azor聊聊RX 6000系列显卡那些事儿
  7. Kubernetes 已经成为云原生时代的安卓,这就够了吗?
  8. 揭秘:如何为 Kubernetes 实现原地升级
  9. 如何在 Knative 中部署 WebSocket 和 gRPC 服务?
  10. 2.3.2 spring属性注入-注解注入-半注解注入-后序