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 ...
随机推荐
- BZOJ 3473
思路: CF原题 ZYF有题解 O(nlog^2n) //By SiriusRen #include <bits/stdc++.h> using namespace std; ; ]; i ...
- 【洛谷4770/UOJ395】[NOI2018]你的名字(后缀数组_线段树合并)
题目: 洛谷4770 UOJ395 分析: 一个很好的SAM应用题-- 一句话题意:给定一个字符串\(S\).每次询问给定字符串\(T\)和两个整数\(l\).\(r\),求\(T\)有多少个本质不同 ...
- tomcat解决 java.lang.IllegalArgumentException: Request header is too large
tomcat运行项目时,有一个请求过去后,后台报这样的错java.lang.IllegalArgumentException: Request header is too large 原因:请求头超过 ...
- 通过HTTP协议实时获取微信聊天记录
第一步:登陆 1.get访问微信首页https://wx.qq.com 提供session.headers 用途:获取cookie 后续访问必须带session.headers.cookie这三个参数 ...
- iOS device is locked/unlocked (判断手机屏幕是否锁屏)
#import <notify.h> -(void)checkDeviceLockScreenState { int notify_token; notify_register_dispa ...
- canvas杂记
canvas杂记 canvas标签 <canvas width=600 height=400></canvas> //1. 拿到画布 var canvas = document ...
- (转)Spring AOP的底层实现技术
AOP概述 软件的编程语言最终的目的就是用更自然更灵活的方式模拟世界,从原始机器语言到过程语言再到面向对象的语言,我们看到编程语言在一步步用更自然.更强大的方式描述软件.AOP是软件开发思想的一个飞跃 ...
- 【译】x86程序员手册17-第6章保护
Chapter 6 Protection 第六章 保护 6.1 Why Protection? 为什么要保护? The purpose of the protection features of th ...
- 3.用Redis Desktop Manager连接Redis(CentOS)
Redis Desktop Manager是Redis图形化管理工具,方便管理人员更方便直观地管理Redis数据. 然而在使用Redis Desktop Manager之前,有几个要素需要注意: 一. ...
- Centos6.4 安装fail2ban防暴力破解
Centos6.4 安装fail2ban防暴力破解 一. 安装 curl -O https://codeload.github.com/fail2ban/fail2ban/tar.gz/0.9.0 m ...