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 ...
随机推荐
- DOM0,DOM2,DOM3事件,事件基础知识入门
事件是javascript和HTML交互基础, 任何文档或者浏览器窗口发生的交互, 都要通过绑定事件进行交互; 事件有DOM0, DOM2和DOM3的区分(别问我怎么少了一个DOM1, 也没找到DOM ...
- 项目总结—jQuery EasyUI- DataGrid使用
http://blog.csdn.net/zwk626542417/article/details/18839349 概要 jQuery EasyUI是一个基于jquery的集成了各种用户界面的框架, ...
- jquery发送ajax请求返回数据格式
jquery向服务器发送一个ajax请求后,可以返回多种类型的数据格式,包括:html,xml,json,text等. 1.html格式的数据 "<div class='comment ...
- ASP.NET WebAPI 03 返回结果
在WebAPI中HttResponseMessage作为消息返回,而在ApiController中我们经常讲四类数据作为返回值,void,object(可序列化),IHttpActionResult, ...
- mlecms v2.2版权
inc\tools\smarty 下的Smarty.class.php文件. 找到 187行左右 我们会发现原来的 $dopud =$_template->libfile($dopud);已经 ...
- WPF 任务栏图标闪烁提醒
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServi ...
- 导出Excel之Epplus使用教程3(图表设置)
导出Excel之Epplus使用教程1(基本介绍) 导出Excel之Epplus使用教程2(样式设置) 导出Excel之Epplus使用教程3(图表设置) 导出Excel之Epplus使用教程4(其他 ...
- TaskTracker任务初始化及启动task源码级分析
在监听器初始化Job.JobTracker相应TaskTracker心跳.调度器分配task源码级分析中我们分析的Tasktracker发送心跳的机制,这一节我们分析TaskTracker接受JobT ...
- PHP访问,增删改查,小结
PHP访问数据,增,删,改,查 增: 1,add.php 显示页面,利用 <form> 表单添加数据,数据添加到 name 中. 2,addchuli.php 处理页面,定义变量接受 $_ ...
- Merge Sort
#include<stdlib.h> #include<stdio.h> void Merge( int source[] , int temp[] , int start , ...