# 2014 GCJ Round 1B New Lottery Game(数位dp，x小于等于A,y小于等于B，并且x&y值小于等于K的数字个数)

2014 GCJ Round 1B New Lottery Game

xA,yB$x\leq A,y\leq B$，并且x$x$&y$y$值小于等于K$K$的数字个数。

// GCJ 2014 #Round1B New Lottery Game

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long ll;

int T, cases = 0;
ll A, B, K;
ll vis[35][3][3][3];

ll solve(int cur, int lessA, int lessB, int lessK)
{
if (cur == -1) return lessA && lessB && lessK;
if (vis[cur][lessA][lessB][lessK] != -1) return vis[cur][lessA][lessB][lessK];
int MaxA = lessA || ((A >> cur) & 1);
int MaxB = lessB || ((B >> cur) & 1);
int MaxK = lessK || ((K >> cur) & 1);
ll ret = solve(cur - 1, MaxA, MaxB, MaxK); // 0 & 0 = 0
if (MaxA) ret += solve(cur - 1, lessA, MaxB, MaxK); // 0 & 1 = 0
if (MaxB) ret += solve(cur - 1, MaxA, lessB, MaxK); // 1 & 0 = 0
if (MaxA && MaxB && MaxK) ret += solve(cur - 1, lessA, lessB, lessK); // 0 & 0 = 0
return vis[cur][lessA][lessB][lessK] = ret;
}

int main()
{
scanf("%d", &T);
while (T--) {
scanf("%lld%lld%lld", &A, &B, &K);
memset(vis, -1, sizeof(vis));
printf("Case #%d: %lld\n", ++cases, solve(31, 0, 0, 0));
}
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：2014 GCJ Round 1B New Lottery Game(数位dp，x小于等于A,y小于等于B，并且x&y值小于等于K的数字个数) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)