HDU - 3271SNIBB 数位dp

xiaoxiao2021-02-28  113

题目:有2中询问,

1:X,Y,B,M   在X到Y中的数转换成B进制之后,有多少个数满足他的每一位数的和是M

2:X,Y,B,M,K  在X到Y中的数转换成B进制之后,第K个  满足他的每一位数的和是M的数使多少

思路:dp[i][j]:转化成B进制后,长度为i的数中,数字和为j的数字有多少个

代码:

#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<algorithm> #include<ctime> #include<cstdio> #include<cmath> #include<cstring> #include<string> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<list> #include<numeric> using namespace std; #define LL long long #define ULL unsigned long long #define INF 0x3f3f3f3f3f3f3f3f #define mm(a,b) memset(a,b,sizeof(a)) #define PP puts("*********************"); template<class T> T f_abs(T a){ return a > 0 ? a : -a; } template<class T> T gcd(T a, T b){ return b ? gcd(b, a%b) : a; } template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} // 0x3f3f3f3f3f3f3f3f int dp[35][305],dight[35]; void Init(int base,int M){ mm(dp,0); dp[0][0]=1; for(int i=1;i<=32;i++) for(int j=0;j<=M;j++){ if(dp[i-1][j]==0) continue; for(int k=0;k<base&&j+k<=M;k++) dp[i][j+k]+=dp[i-1][j]; } } int solve(int n,int base,int M){ if(n<0) return 0; int len=0; do{ dight[++len]=n
转载请注明原文地址: https://www.6miu.com/read-37575.html

最新回复(0)