HDU 4389 X mod f (x) (Digital DP)
For the first time, you need to enumerate and then digit DP.
First, enumerate the sum of all numbers, that is, 1 ~ 81. Then, in the digital DP process, judge whether the sum of the enumerated numbers is the same as that of the enumerated numbers.
Dp [I] [j] [k] [h] indicates that, on the I-bit, the current number is j, and the enumerated number is k, the number of k modulo h for the current number pair.
The Code is as follows:
#include
#include
#include
#include
#include #include
#include
#include
#include
using namespace std;#define LL __int64#define pi acos(-1.0)const int mod=1e9+7;const int INF=0x3f3f3f3f;const double eqs=1e-9;const int MAXN=200000+10;int dp[11][82][82][82], dig[11];int dfs(int cnt, int sum, int mods, int res, int maxd){ if(cnt==-1) return sum==mods&&res==0; if(sum>mods) return 0; if(maxd&&dp[cnt][sum][mods][res]!=-1) return dp[cnt][sum][mods][res]; int i, r=maxd?9:dig[cnt], ans=0; for(i=0;i<=r;i++){ ans+=dfs(cnt-1,sum+i,mods,(res*10+i)%mods,maxd||i