HDU 5435
数位DP题,然而不会做。设dp[i][j]表示前i位异或和为j的时候的个数。先dp出所有的可能组合使得异或和为j的个数,然后按位进行枚举。对于dp[i][j],其实不止是前i位,对于后i位的情况同样适用,当在枚举s[i]位时k,如果k<s[i]时,只需直接计算后dp[i][j]的情况就好。。
可见,我其实对于状压、数位DP已经很生疏了,因为这个暑假。。。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring> using namespace std;
#define LL long long
const int MAX=100005;
const int mod=1000000007;
int cnt[MAX][17];
char s[MAX],t[MAX]; void init(){
memset(cnt,0,sizeof(cnt));
cnt[0][0]=1;
for(int i=0;i<10;i++) cnt[1][i]=1;
for(int i=1;i<MAX-1;i++){
for(int j=0;j<16;j++){
for(int k=0;k<=9;k++){
cnt[i+1][j^k]+=cnt[i][j];
cnt[i+1][j^k]=cnt[i+1][j^k]>=mod?cnt[i+1][j^k]-mod:cnt[i+1][j^k];
}
}
}
} LL cal(char s[]){
int cur=0; LL res=0;
int len=strlen(s);
for(int i=0;i<len;i++){
int k=s[i]-'0';
for(int j=0;j<k;j++){
for(int h=0;h<16;h++){
res+=(LL)cnt[len-i-1][h]*(j^h^cur);
}
res%=mod;
}
cur^=k;
}
return res;
} int main(){
init();
int T,kase=0;
scanf("%d",&T);
while(T--){
scanf("%s%s",s,t);
LL ans=cal(t)-cal(s);
int tmp=0,l=strlen(t);
for(int i=0;i<l;i++) tmp^=(t[i]-'0');
ans+=tmp; ans=(ans%mod+mod)%mod;
printf("Case #%d: %lld\n",++kase,ans); }
return 0;
}
HDU 5435的更多相关文章
- hdu 5435 A serious math problem
A serious math problem Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
随机推荐
- ARM VM安装Linux Diagnostic 2.3扩展
目前创建的Azure Linux虚拟机默认安装的是LAD 3.0,如果客户有特殊需求,可以通过如下方法安装LAD 2.3 1.在Azure Portal卸载LAD 3.0 2.使用Azure Powe ...
- Spark 概念学习系列之Spark基本概念和模型(十八)
打好基础,别小瞧它! spark的运行模式多种多样,在单机上既可以本地模式运行,也可以伪分布模式运行.而当以分布式的方式在集群中运行时.底层的资源调度可以使用Mesos或者Yarn,也可使用spark ...
- Task.Run 和 Task.Factory.StartNew
在.Net 4中,Task.Factory.StartNew是启动一个新Task的首选方法.它有很多重载方法,使它在具体使用当中可以非常灵活,通过设置可选参数,可以传递任意状态,取消任务继续执行,甚至 ...
- Unity学习-工具准备(一)
工具介绍 Unity 4.5.4 VS2013 Visual Studio 2013 Tools for Unity unity3d圣典 五大面板 Hierarchy:场景资源面板 [管理 当前场景 ...
- Serializable和Parcelable的简单介绍
Serializable和Pacelable接口可以完成对象的序列化过程,当我们需要通过Intent和Binder传输数据时就需要使用Parcelable或者Serializable. Seriali ...
- jQuery——节点操作
创建节点 1.$():创建一个li标签 $("<li class='aaa'>我是li标签</li>") 2.html():创建一个li标签并同时添加到ul ...
- Java_Web三大框架之Hibernate+jsp+HQL分页查询
分页查询无处不在.使用Hibernate+jsp+HQL进行分页查询. 第一步:编写房屋实体类和House.hbm.xml映射. /* * 房屋实体类 */ public class House { ...
- 在PHP中调用php_ssh实现远程登陆linux服务器并执行shell脚本。
这个功能主要用于在web端利用程序对远程服务器进行操作,通过PHP_ssh执行shell脚本来实现. 首先要安装php_ssh2组件,linux中centos7下有ssh2源,直接安装.window下 ...
- (转)Arcgis for JS之Cluster聚类分析的实现
http://blog.csdn.net/gisshixisheng/article/details/40711075 在做项目的时候,碰见了这样一个问题:给地图上标注点对象,数据是从数据库来的,包含 ...
- (转)Struts2快速入门
http://blog.csdn.net/yerenyuan_pku/article/details/66187307 Struts2框架的概述 Struts2是一种基于MVC模式的轻量级Web框架, ...