感觉自己思维僵化,大佬们的代码总是那么优秀!
题解:感觉连dp都算不上就是一个递推式就结束了,我竟然还想了老半天!一个数的种类=用最高位+不用最高位;结束!
f(x,y)=f(x-2^(y-1),y-1)+f(x,y-1);
代码:
#include<cstdio> #include<cmath> #include<cstring> #include<iostream> using namespace std; int km(int n) { int base=2,p=1; while(n) { if(n&1) p*=base; base*=base; n>>=1; } return p; } long long f(int x,int y) { if(x<0)x=-x; if(x>=km(y))return 0; if(x==0)return 1; if(y==1)if(x==1)return 1;else return 0; return f(x-km(y-1),y-1) + f(x,y-1); } int main() { //freopen("input.txt","r",stdin); int T;scanf("%d",&T); while(T--) { int x,y; scanf("%d %d",&x,&y); printf("%lld ",f(x,y)); } return 0; }