HDU6148

简单的数位DP。只需要判断是否在递减之前出现过递增
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define nl n<<1
#define nr (n<<1)|1
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pairP;
const int INF=0x3f3f3f3f;
const ll INFF=0x3f3f3f3f3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-9;
const ll mod=1e9+7;
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' | ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void Out(int aa)
{
    if(aa>9)
        Out(aa/10);
    putchar(aa%10+'0');
}
long long dp[105][105][10][2][2];
int s[105];
char str[105];
ll rec(int i,int pre,int up,int down,int flag,int q,int len)
{
    if(i<0)
        return 1;
    if(dp[i][len][pre][up][down]!=-1&&!flag&&!q)
        return dp[i][len][pre][up][down];
    ll res=0;
    int o=s[i];
    for(int j=0; j<10; j++)
    {
        if(j>o&&flag)
            break;
        if(q)
            res+=rec(i-1,j,0,0,jpre)
        {
            res+=rec(i-1,j,1,down,j

你可能感兴趣的:(动态规划)