Google Code Jam 2014 Round 1B Problem B
二进制数位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的更多相关文章
- 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 ...
- 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 ...
- Google Code Jam 2016 Round 1B Problem C. Technobabble
题目链接:https://code.google.com/codejam/contest/11254486/dashboard#s=p2 大意是教授的学生每个人在纸条上写一个自己的topic,每个to ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- C# 中的多线程
参考网站http://blog.gkarch.com/topic/threading.html
- 【CodeForces 622A】Infinite Sequence
题意 一个序列是, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5....这样排的,求第n个是什么数字. 分析 第n个位置属于1到k,求出k,然后n-i*(i-1)/ ...
- 打印cell的视图层次结构
#ifdef DEBUG NSLog(@"Cell recursive description:\n\n%@\n\n", [cell performSelector:@select ...
- BZOJ-2875 随机数生成器 矩阵乘法快速幂+快速乘
题目没给全,吃X了... 2875: [Noi2012]随机数生成器 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 1479 Solved: 829 ...
- 【bzoj3150】 cqoi2013—新Nim游戏
www.lydsy.com/JudgeOnline/problem.php?id=3105 (题目链接) 题意 在第一个回合中,第一个游戏者可以直接拿走若干个整堆的火柴.可以一堆都不拿,但不可以全部拿 ...
- sql prompt5安装好了 也破解完成了 然后到SQL里面 还是没有提示 是为什么?
勾上这个,祝你成功!
- 洛谷P1417 烹调方案
题目背景 由于你的帮助,火星只遭受了最小的损失.但gw懒得重建家园了,就造了一艘飞船飞向遥远的earth星.不过飞船飞到一半,gw发现了一个很严重的问题:肚子饿了~ gw还是会做饭的,于是拿出了储藏的 ...
- POJ1979 Red and Black
速刷一道DFS Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
- Linux中断技术、门描述符、IDT(中断描述符表)、异常控制技术总结归类
相关学习资料 <深入理解计算机系统(原书第2版)>.pdf http://zh.wikipedia.org/zh/%E4%B8%AD%E6%96%B7 独辟蹊径品内核:Linux内核源代码 ...
- Spring学习4-面向切面(AOP)之Spring接口方式
一.初识AOP 关于AOP的学习可以参看帮助文档:spring-3.2.0.M2\docs\reference\html目录下index.html的相关章节 1.AOP:Aspect ...