二进制数位DP,涉及到数字的按位与操作。

查看官方解题报告

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std; #define MAX_LEN 50 long long A, B, K;
int a[MAX_LEN], b[MAX_LEN], k[MAX_LEN];
long long memoize[MAX_LEN][][][]; void input()
{
scanf("%lld%lld%lld", &A, &B, &K);
} int convert(long long A, int a[])
{
int i = ;
while (A)
{
a[i] = A & ;
A >>= ;
i++;
}
return i;
} long long dfs(int current_bit, bool less_a, bool less_b, bool less_k)
{
if (current_bit == -)
{
if (less_a && less_b && less_k)
{
return ;
}
return ;
}
if (memoize[current_bit][less_a][less_b][less_k] != -)
return memoize[current_bit][less_a][less_b][less_k];
bool one_a = less_a || a[current_bit] == ;
bool one_b = less_b || b[current_bit] == ;
bool one_k = less_k || k[current_bit] == ;
// a0 b0
long long ret = dfs(current_bit - , one_a, one_b, one_k);
// a1 b0
if (one_a)
{
ret += dfs(current_bit - , less_a, one_b, one_k);
}
// a0 b1
if (one_b)
{
ret += dfs(current_bit - , one_a, less_b, one_k);
}
// a1 b1
if (one_a && one_b && one_k)
{
ret += dfs(current_bit - , less_a, less_b, less_k);
}
return memoize[current_bit][less_a][less_b][less_k] = ret;
} int main()
{
int t;
scanf("%d", &t);
for (int i = ; i < t; i++)
{
printf("Case #%d: ", i + );
input();
memset(a, , sizeof(a));
memset(b, , sizeof(b));
memset(k, , sizeof(k));
convert(A, a);
convert(B, b);
convert(K, k);
memset(memoize, -, sizeof(memoize));
long long ans = dfs(, false, false, false);
printf("%lld\n", ans);
}
return ;
}

Google Code Jam 2014 Round 1B Problem B的更多相关文章

  1. Google Code Jam 2010 Round 1B Problem B. Picking Up Chicks

    https://code.google.com/codejam/contest/635101/dashboard#s=p1   Problem A flock of chickens are runn ...

  2. Google Code Jam 2010 Round 1B Problem A. File Fix-it

    https://code.google.com/codejam/contest/635101/dashboard#s=p0   Problem On Unix computers, data is s ...

  3. Google Code Jam 2016 Round 1B Problem C. Technobabble

    题目链接:https://code.google.com/codejam/contest/11254486/dashboard#s=p2 大意是教授的学生每个人在纸条上写一个自己的topic,每个to ...

  4. Google Code Jam 2010 Round 1C Problem A. Rope Intranet

    Google Code Jam 2010 Round 1C Problem A. Rope Intranet https://code.google.com/codejam/contest/61910 ...

  5. Google Code Jam 2014 资格赛:Problem B. Cookie Clicker Alpha

    Introduction Cookie Clicker is a Javascript game by Orteil, where players click on a picture of a gi ...

  6. Google Code Jam 2014 Round 1 A:Problem C. Proper Shuffle

    Problem A permutation of size N is a sequence of N numbers, each between 0 and N-1, where each numbe ...

  7. Google Code Jam 2010 Round 1C Problem B. Load Testing

    https://code.google.com/codejam/contest/619102/dashboard#s=p1&a=1 Problem Now that you have won ...

  8. Google Code Jam 2014 资格赛:Problem D. Deceitful War

    This problem is the hardest problem to understand in this round. If you are new to Code Jam, you sho ...

  9. Google Code Jam 2014 Round 1 A:Problem A Charging Chaos

    Problem Shota the farmer has a problem. He has just moved into his newly built farmhouse, but it tur ...

随机推荐

  1. uva12532 线段树单点更新

    #include<stdio.h> #include<string.h> #include<queue> using namespace std; #define ...

  2. strncmp很好的函数

    strcmp比较的是所有的长度,而strncmp可以比较前几个长度 strncmp(s1,s2,n);这样就比较了s1,s2,前n个长度的大小.

  3. 在Eclipse 中下载 开源中国码云上的项目

    功能:使用开源中国代码托管(码云)来托管代码,本地的使用Eclipse,该如何配置? 步骤: 1/  在码云 上建一个工程,(为了访问托管工程的权限) 2/  在eclipse中打开名字叫做“Git ...

  4. jquery插件库

    jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多javascript高手加入其team. jQuery是继prototype之后又一个优秀的Javascrīpt框架.其经典 ...

  5. 【POJ 2250】Compromise(最长公共子序列LCS)

    题目字符串的LCS,输出解我比较不会,dp的时候记录从哪里转移来的,之后要一步一步转移回去把解存起来然后输出. #include<cstdio> #include<cstring&g ...

  6. 使用U盘安装mint

    系统坏了,重新装的时候,硬盘甚至都没法格式化...所以,狠狠心买了块固态硬盘,123G,威刚. 想自己装Linux系统,这样用起来更方便一点,不用装虚拟机,然后再跑linux什么的.最后选了mint. ...

  7. groovy–运算符重载

    Groovy支持运算符重载,各种运算符被映射到普通的java对象的方法调用,这就使得开发者可以利用运算符重载的优势来编写自己的Java或者groovy对象. 下面的表格描述了groovy中的操作符所映 ...

  8. HDU #5507 GT and Strings

    这是AC自动机系列的第一篇 传送门 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Othe ...

  9. PL/0编译器(java version) - MainFrame.java

    1: /* 2: * To change this license header, choose License Headers in Project Properties. 3: * To chan ...

  10. 多线程java代码移植到android&下载文本界面的更新

    1)效果演示: