[1545] New Year 2014(数位DP,现放标程,待看)
来源:互联网 发布:wex5 php 后端开发 编辑:程序博客网 时间:2024/04/28 16:26
1、http://acm.nbut.edu.cn/Problem/view.xhtml?id=1545
2、题目
[1545] New Year 2014
In the New Year 2014, Xiao Ming is thinking about the question: give two integers Nand K, Calculate the number of the numbers of satisfy the following conditions:
1. It is a positive integer and is not greater than N.
2. Xor value of its all digital is K.
For example N = 12, K = 3, the number of satisfy condition is 3 and 12(3 = 3, 1 ^ 2 = 3).
In order to let Xiao Ming happy in the New Year 2014, can you help him?
There are multiple test cases, each test sample contains two positive integers N and K (0 <= N, K < 10 ^ 18), End to file.
For each case, output the number of the numbers of satisfy condition in one line.
12 3999 512354 8
276662
无
宁静致远 @HBMY
3、比赛标程
简单的数位DP, dp[pos][statu] (statu 为异或值)!
本题有个trick, k等于0的时候要将答案减一(题目中要求数都为正的).
#include<cstdio>#include<cstring>#include<iostream>using namespace std;#define lint long longint bit[30];lint dp[30][20];lint dfs(int pos,int x,bool limit){ if(pos<0) { if(limit)return 0; else return x==0; } if(!limit&&dp[pos][x]!=-1)return dp[pos][x]; int end=(limit==0)?9:bit[pos]; lint ans=0; for(int i=0;i<=end;++i) { ans+=dfs(pos-1,i^x,limit&&(i==end)); } dp[pos][x]=ans; return ans;}lint solve(lint n,int x){ int len=-1; memset(dp,-1,sizeof(dp)); while(n) { bit[++len]=n%10; n/=10; } return dfs(len,x,1);}int main(){ //freopen("G:\\1.in","r",stdin); //freopen("G:\\1.out","w",stdout); lint n,x; while(cin>>n>>x) { if(x>15) { puts("0"); continue; } lint ans=solve(n+1,x); if(x==0)--ans; printf("%lld\n",ans); } return 0;}
0 0
- [1545] New Year 2014(数位DP,现放标程,待看)
- nbut 1545 New Year 2014 数位dp
- NOJ1545---New Year 2014(数位dp)
- [1545] New Year 2014
- nbut [1545] New Year 2014
- NBUT [1545] New Year 2014
- Good Bye 2014 D. New Year Santa Network 树形dp
- New Year Bonus Grant(SGU195,贪心or区间DP)
- Codeforces 611C New Year and Domino(dp)
- CodeForces 611 D. New Year and Ancient Prophecy(dp)
- CodeForces 500 D. New Year Santa Network(树形DP)
- CF Good Bye 2015 C. New Year and Domino && D. New Year and Ancient Prophecy (DP)
- sgu195:New Year Bonus Grant(树形dp)
- Good Bye 2015-New Year and Days(看日历找规律)
- codeforces 500D - New Year Santa Network (树形DP+组合数学)
- Good Bye 2015 D. New Year and Ancient Prophecy(dp+LCP)
- CodeForces 611 C. New Year and Domino(dp+容斥)
- 【CF 140E】New Year Garland(第二类斯特林(Stirling)数+DP+容斥)
- 如何将字节数组转换为十六进制的字符串
- Oil Deposits
- JDBC,MYBATIS,Hibernate性能对比!
- 全局变量 局部变量 堆 栈
- array_filter
- [1545] New Year 2014(数位DP,现放标程,待看)
- ExtJs xtype一览
- 源码推荐(2月12日):高效低内存音频播放引擎 基于NSXMLParser的Objective-C XML阅读器
- android wifi休眠策略
- python fabric实现远程操作和部署
- Android之BaseExpandableListAdapter的用法
- backlight子系统二
- Confluence 贡献人摘要(Contributors Summary)宏
- 两表测试SQL语句