SRM 595 DIV2 1000

时间:2023-03-09 04:51:57
SRM 595 DIV2 1000

数位DP的感觉,但是跟模版不是一个套路的,看的题解,代码好理解,但是确实难想。

 #include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define LL long long
LL dp[][][][];
int a[],b[],c[];
void fun(int *p,int x)
{
int i;
for(i = ; i <= ; i ++)
{
if(x&(<<i))
p[i] = ;
else
p[i] = ;
}
}
LL dfs(int pos,int ta,int tb,int tc)
{
if(pos == -)
return ;
LL & res = dp[pos][ta][tb][tc];
int x,y,z;
if(res == -)
{
res = ;
for(x = ; x < ; x ++)
{
for(y = ; y < ; y ++)
{
z = x^y;
if((!ta||(x <= a[pos]))&&(!tb||(y <= b[pos]))&&(!tc||(z <= c[pos])))
{
res += dfs(pos-,ta&&(x == a[pos]),tb&&(y == b[pos]),tc&&(z == c[pos]));
}
}
}
}
return res;
}
class LittleElephantAndXor
{
public :
LL getNumber(int A, int B, int C)
{
memset(dp,-,sizeof(dp));
fun(a,A);
fun(b,B);
fun(c,C);
return dfs(,,,);
}
};