Number of topics P4317 Flora dynamic programming? Digital DP

Ideas: Digital $ DP $

Submission: 5 (in fact, before A before, but adjusted the original program this is twice the AC.)

answer:

We are determined $ sum (x) = i $, for a $ i $, there are several $ x $, then we can quickly solve power.

As required by the number of the DP digit $ $ like.

#include<cstdio>
#include<iostream>
#include<cstring>
#define ull unsigned long long
#define ll long long
#define R register ll
using namespace std;
#define pause (for(R i=1;i<=10000000000;++i))
#define In freopen("NOIPAK++.in","r",stdin)
#define Out freopen("out.out","w",stdout)
namespace Fread {
static char B[1<<15],*S=B,*D=B;
#ifndef JACK
#define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
#endif
inline ll g() {
    R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix;
    if(ch==EOF) return EOF; do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix;
} inline bool isempty(const char& ch) {return (ch<=36||ch>=127);}
inline void gs(char* s) {
    register char ch; while(isempty(ch=getchar()));
    do *s++=ch; while(!isempty(ch=getchar()));
}
} using Fread::g; using Fread::gs;

namespace Luitaryi {
const int N=51,M=1e7+7;
ll n;
int len,num[N];
ll f[N][N];
inline int qpow(ll a,ll p) { R ret=1; a%=M;
    for(; P; P >> = . 1 , (A * = A)% = M) IF (P & . 1 ) (RET * = A)% = M; return RET; 
} 
inline LL DFS ( int L, BOOL UL, int C, int D) { // L: length, ul: upper bound tag, c: count the number 1, d: the number of a request (i.e., at this time we make SUM (X) = D) 
    IF (L! ) return C == D;
     IF (UL && ~ F [L] [C])! return F [L] [C]; 
    R & lt Lim = (UL NUM [L]:? . 1 ), CNT = 0 ;
     for (R & lt = I 0 ; I <= Lim; ++ I) 
        CNT + = DFS (L- . 1,ul&&i==lim,c+i,d);
    return ul?cnt:f[l][c]=cnt;
}
inline int solve(ll n) { R ans=1;
    for(;n;n>>=1) num[++len]=n&1; 
    for(R i=1;i<=len;++i) 
        memset(f,0xff,sizeof(f)),
        ans=(ans*qpow(i,dfs(len,true,0,i)))%M;
    return ans;
}
inline void main() {
    n=g(); printf("%d\n",solve(n));
}
}
signed main() {
    Luitaryi::main(); return 0;
}

2019.07.21

 

Guess you like

Origin www.cnblogs.com/Jackpei/p/11223484.html