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 ...
随机推荐
- form表单提交和ajax提交的区别
form表单是整个页面跳到服务器的地址然后提交数据: ajax是往这个地址post数据 <form style="padding:0px;margin:0px;" targe ...
- 【POJ 1062】昂贵的聘礼(最短路)
Dijkstra最短路,每次限制一个等级差,再更新答案. #include <cstdio> #define N 105 #define INF 1e9 int m, n; int p[N ...
- 萤火虫算法-python实现
FAIndividual.py import numpy as np import ObjFunction class FAIndividual: ''' individual of firefly ...
- 高斯混合聚类及EM实现
一.引言 我们谈到了用 k-means 进行聚类的方法,这次我们来说一下另一个很流行的算法:Gaussian Mixture Model (GMM).事实上,GMM 和 k-means 很像,不过 G ...
- 【bzoj1046】 HAOI2007—上升序列
http://www.lydsy.com/JudgeOnline/problem.php?id=1046 (题目链接) 题意 给出一个数列,求数列中长度为L的下标字典序最小的上升子序列. Soluti ...
- 【linux基础】第九周作业
1.详细描述一次加密通讯的过程,结合图示最佳. 加密通讯:A <--> B 1)A与 B通信,首先A.B双方都应该持有对方的公钥,即证书,并验证证书的合法性. 2)加密: i. A ...
- PHP中的替代语法(转)
我们经常在wordpress一类博客程序的模板里面看到很多奇怪的PHP语法,比如: <?php if(empty($GET_['a'])): ?> <font color=" ...
- MVC利用Routing实现多域名绑定一个站点、二级域名以及二级域名注册Area
最近有这么个需求:在一个站点上绑定多个域名,每个域名进去后都要进入不同的页面.实现了这个功能以后,对于有多个域名,且有虚拟空间,但是虚拟空间却只匹配有一个站点的用户来说,可以节省很多小钱钱. 很久以前 ...
- Linux 查看CPU,内存,硬盘 !转
Linux 查看CPU,内存,硬盘 本文转自:http://hi.baidu.com/mumachuntian/item/a401368dbe8a66cab07154e8 1 查看CPU 1.1 查看 ...
- HDOJ 1907 John
对于任意一个 Anti-SG 游戏,如果我们规定当局面中所有的单一游戏的 SG 值为 0 时,游戏结束,则先手必胜当且仅当: (1)游戏的 SG 函数不为 0 且游戏中某个单一游戏的 SG 函数大于 ...