数位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;
}

最新文章

  1. 安卓刷机--fastboot线刷
  2. KBMMW 4.92.00 发布
  3. cocos2dx release note
  4. 2016年6月28日 星期二 --出埃及记 Exodus 14:25
  5. gcc和ld 中的参数 --whole-archive 和 --no-whole-archive
  6. make menuconfig出错需要安装文件
  7. linux(centos)如何查看文件夹大小
  8. Linq101-Element
  9. 教你用Perl 实现Base64编码
  10. WEB安全入门
  11. Java知识补充
  12. DOM元素拖拽效果
  13. 好用的开源库(二)——uCrop 图片裁剪
  14. PHP 变量的实现原理
  15. Spring Security OAuth2 Demo -- good
  16. Docker报错 WARNING: IPv4 forwarding is disabled. Networking will not work.
  17. 7.6 GRASP原则六: 多态 Polymorphism
  18. 在 Ubuntu 上安装 TensorFlow (官方文档的翻译)
  19. [JS] js数字位数太大导致参数精度丢失问题
  20. CodeForces - 285E: Positions in Permutations(DP+组合数+容斥)

热门文章

  1. HTML-ul分分钟理解
  2. python网络爬虫之图片链家在技术.seleninum和PhantonJS
  3. C与C艹的内存管理方式
  4. Extension Methods(扩展方法)
  5. 联想 A5(L18011) 免解锁BL 免rec Magisk Xposed ROOT 救砖 ZUI 3.9.068
  6. win32之bitmap篇
  7. Angular——自定义指令
  8. C# 字符串的入门
  9. Windows 8 常见教程
  10. js 闭包 定时器