二进制数位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. 【BZOJ 1036】【ZJOI 2008】树的统计 树链剖分模板题

    sth神犇的模板: //bzoj1036 题目:一个n个点的树每个点有一个权值,支持修改单点权值,求某两点路径上的点权和或最大点权. #include <cstdio> using nam ...

  2. 负margin一些奇葩的布局技巧

    copy_from_ http://www.hicss.net/i-know-you-do-not-know-the-negative-margin/ <!doctype html> &l ...

  3. ORACLE数据库删除表中记录报record is locked by another user

    在操作ORACLE数据库的时候,由于执行完,没有COMMIT,直接把PL/SQL关闭掉,后来导致那张表被锁住,当编辑时就会出现这个信息,record is locked by another user ...

  4. STL简单应用问题

    问题: Input输入的第一行是一个整数T( 1 <= T <= 100 ),表示有几组输入数据.每组输入由4部分组成:(1)一个字典,最多包含2000个单词,每个单词一行.(2)一行字符 ...

  5. AU3学习资源

    AU3中文站:http://www.autoitx.com/

  6. ZOJ 2110 Tempter of the Bone

    Tempter of the Bone Time Limit: 2 Seconds      Memory Limit: 65536 KB The doggie found a bone in an ...

  7. intent属性

    private String mAction;private Uri mData;private String mType;private String mPackage;private Compon ...

  8. Note:JSON

    JSON是JavaScript的原生格式,意味着在JavaScript中处理JSON数据不需要特殊的API或工具包,它是完全独立于语言的文本格式,可以把JavaScript对象中的一组对象转化为字符串 ...

  9. The illustrated guide to a Ph.D.

  10. CodeForces 701A Cards

    直接看示例输入输出+提示 1. 统计所有数的和 sum,然后求 sum/(n/2) 的到一半数的平均值 6 1 5 7 4 4 3 ->1+5+7+4+4+3=24  分成3组 每组值为8 in ...