ural 1310 数位dp

这题和spoj 2319很相像,都是数位dp+大数。

spoj 2319可以参考论文——2009 - 刘聪《浅谈数位类统计问题》。

读入n,m,k,还有一个大数

dp[i][j](1<=i<=n,0<=j<k)表示用i位表示的数模k余j的数的个数

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <iostream>
#include <string>
#include <cstdlib>
#include <map>
#define pb push_back
#define eps 1e-9
#define zero(x) (fabs(x)<eps)
#define pi acos(-1.0)
#define MS(x, y) memset(x, y, sizeof(x))
#define FOR(i, x, y) for(int i=x; i<=y; i++)
#define rFOR(i, x, y) for(int i=x; i>=y; i--)
using namespace std;
const int maxn = 175;
struct bigint
{
    int s[maxn];

    bigint() {MS(s, 0);}
    bigint(int num) {*this = num;}
    bigint(const char* num){*this = num;}

    bigint operator = (const char* num)
    {
        MS(s, 0);
        if(num[0] == '-')
        {
            num = num + 1;
            s[0] = -1;
        }
        else s[0] = 1;
        while(num[0] == '0') num = num + 1;
        s[0] = s[0] * strlen(num);
        int len = abs(s[0]);
        FOR(i, 1, len) s[i] = num[len - i] - 48;
        return *this;
    }
    bigint operator = (int num)
    {
        char s[maxn];
        sprintf(s, "%d", num);
        *this = s;
        return *this;
    }

    string str() const
    {
        string res = "";
        FOR(i, 1, abs(s[0])) res = (char)(s[i] + 48) + res;
        if(res == "") return res = "0";
        if(s[0] < 0) res = '-' + res;
        return res;
    }

    bool operator < (const bigint& b) const
    {
        if(s[0] != b.s[0]) return s[0] < b.s[0];
        int len = abs(s[0]);
        rFOR(i, len, 1)
        if(s[i] != b.s[i])
            return (s[i] < b.s[i]) ^ (s[0] < 0);
        return false;
    }
    bool operator > (const bigint& b) const{return b < *this;}
    bool operator <= (const bigint& b) const{return !(b < *this);}
    bool operator >= (const bigint& b) const{return !(*this < b);}
    bool operator != (const bigint& b) const{return b < *this || *this < b;}
    bool operator == (const bigint& b) const{return !(b < *this) && !(*this < b);}

    friend bigint abs(bigint b)
    {
        b.s[0] = abs(b.s[0]);
        return b;
    }
    friend bigint _add(const bigint& a, const bigint& b)
    {
        bigint c;
        c.s[0] = max(a.s[0], b.s[0]);
        FOR(i, 1, c.s[0]) c.s[i] = a.s[i] + b.s[i];
        FOR(i, 1, c.s[0])
        if(c.s[i] >= 10)
        {
            c.s[i+1]++;
            c.s[i]-=10;
        }
        if(c.s[c.s[0]+1]) ++c.s[0];
        return c;
    }
    friend bigint _sub(const bigint& a, const bigint& b)
    {
        bigint c;
        c.s[0] = a.s[0];
        FOR(i, 1, c.s[0]) c.s[i] = a.s[i] - b.s[i];
        FOR(i, 1, c.s[0])
        if(c.s[i] < 0)
        {
            c.s[i+1]--;
            c.s[i] += 10;
        }
        while(!c.s[c.s[0]] && c.s[0]) --c.s[0];
        return c;
    }
    bigint operator + (const bigint& b) const
    {
        if(s[0] >= 0 && b.s[0] >= 0) return _add(*this, b);
        if(b.s[0] < 0) return *this - abs(b);
        if(s[0] < 0) return b - abs(*this);
    }
    bigint operator - (const bigint& b) const
    {
        if(s[0] >= 0 && b.s[0] >= 0)
        {
            bigint c;
            if(*this >= b) return _sub(*this, b);
            c = _sub(b, *this);
            c.s[0] = -c.s[0];
            return c;
        }
        if(b.s[0] < 0) return *this + abs(b);
        if(s[0] < 0)
        {
            bigint c;
            c = abs(*this) + b;
            c.s[0] = -c.s[0];
            return c;
        }
    }
    bigint operator * (const bigint& b) const
    {
        bigint c;
        c.s[0] = abs(s[0]) + abs(b.s[0]);
        FOR(i, 1, abs(s[0]))
        FOR(j, 1, abs(b.s[0]))
            c.s[i + j - 1] += s[i] * b.s[j];
        FOR(i, 1, c.s[0])
        {
            c.s[i+1] += c.s[i] / 10;
            c.s[i] %= 10;
        }
        while(!c.s[c.s[0]] && c.s[0]) --c.s[0];
        if((s[0] > 0) != (b.s[0] > 0)) c.s[0] = -c.s[0];
        return c;
    }
    bigint operator / (const bigint& _b) const
    {
        bigint c, t;
        bigint b = abs(_b);
        c.s[0] = abs(s[0]);
        rFOR(i, c.s[0], 1)
        {
            rFOR(j, t.s[0], 1) t.s[j + 1] = t.s[j];
            t.s[1] = s[i];
            if (t.s[t.s[0]+1])t.s[0]++;

            while(t >= b)
            {
                ++c.s[i];
                t -= b;
            }
        }
        while(!c.s[c.s[0]] && c.s[0]) --c.s[0];
        if((s[0] > 0) != (b.s[0] > 0)) c.s[0] = -c.s[0];
        return c;
    }
    bigint operator % (const bigint& _b) const
    {
        bigint c, t;
        bigint b = abs(_b);
        rFOR(i, abs(s[0]), 1)
        {
            rFOR(j, t.s[0], 1) t.s[j + 1] = t.s[j];
            t.s[1] = s[i];
            if (t.s[t.s[0]+1])t.s[0]++;

            while(t >= b) t -= b;
        }
        if((s[0] < 0)) t.s[0] = -t.s[0];
        return t;
    }

    bigint operator += (const bigint& b) {*this = *this + b;return *this;}
    bigint operator -= (const bigint& b) {*this = *this - b;return *this;}
    bigint operator *= (const bigint& b) {*this = *this * b;return *this;}
    bigint operator /= (const bigint& b) {*this = *this / b;return *this;}
    bigint operator %= (const bigint& b) {*this = *this % b;return *this;}

    friend bigint operator + (int& a, const bigint& b){return (bigint)a + b;}
    friend bigint operator - (int& a, const bigint& b){return (bigint)a - b;}
    friend bigint operator * (int& a, const bigint& b){return (bigint)a * b;}
    friend bigint operator / (int& a, const bigint& b){return (bigint)a / b;}
    friend bigint operator % (int& a, const bigint& b){return (bigint)a % b;}

    friend bigint operator <  (int& a, const bigint& b){return (bigint)a < b;}
    friend bigint operator <= (int& a, const bigint& b){return (bigint)a <=b;}
    friend bigint operator >  (int& a, const bigint& b){return (bigint)a > b;}
    friend bigint operator >= (int& a, const bigint& b){return (bigint)a >=b;}
    friend bigint operator == (int& a, const bigint& b){return (bigint)a ==b;}
    friend bigint operator != (int& a, const bigint& b){return (bigint)a !=b;}
};
istream& operator >> (istream &in, bigint& x)
{
    string s;
    in >> s;
    x = s.c_str();
    return in;
}
ostream& operator << (ostream &out, const bigint& x)
{
    out << x.str();
    return out;
}

using namespace std;
int l,m,k;
bigint x;
bigint dp[101][50];
void doit()
{
    cin>>x;x+=1;
    for (int z=0;z<k;z++)
        dp[0][z]=0;
    dp[0][0]=1;
    for (int i=1;i<=l;i++)
        {   for (int z=0;z<k;z++)
                dp[i][z]=0;
            for (int j=1;j<=m;j++)
            for (int z=0;z<k;z++)
                dp[i][(z+j)%k]+=dp[i-1][z];

        }

    int w=l,i,p=0;
    bool have=0;
    bigint tmp;
    while (w)
        {   for (i=1;i<=m;i++)
                {  tmp=dp[w-1][((p-i)%k+k)%k];
                   if (x<=tmp) break;else x-=tmp;
                }
            if (have) printf(" "); have=1;
            printf("%d",i);
            w--;
            p=((p-i)%k+k)%k;
        }
    printf("\n");
}

int main()
{   while (scanf("%d%d%d",&l,&m,&k)!=EOF) doit();
}
/*
3 10 4
213
*/


易表.net 10.3 Build 1310 +龙族小萝卜完美注册+串口硬盘注册需的修改器+易表运行环境以及注册说明 说明:(含易表1310原版,小萝卜注册机,ProcessLook2内存编辑工具内存编辑器(串口硬盘注册用),WinHex内存编辑器,易表运行环境egdvmchs1715(打包发布程序用),图片型的注册指导) 0:有要程序发布的同学,需要易表10.3 Build 1310 的运行环境的同学可以单独联系我:<victor_99_love@qq.com> 1:本版为易表.net 10.3 Build 1310 +龙族小萝卜完美注册机(唯一一个完全破解版本)+串口硬盘注册需的内存在修改器以及使用说明 2:内附的注册机为龙族小萝卜破解的,在这之后,易表就通过运营方式让破解网站没有参与破解易表的行动中来,所以也只有这么一个完全破解版本。注册机大小601KB,绝对不是你手上那种6KB或8KB大小的。本版解除了所有暗桩,从破解之初到现在2013年,群里朋友实际使用,无任何异常。 3:解决了串口硬盘的注册问题:注册机本身只针对并口硬盘,在串口硬盘注册时,请参照内附的注册说明(有图片) 4:对使用内存编辑器进行注册的步骤,因比较繁琐,所以专门做了一个图片帮助,方便大家对照图片过程进行注册。 5:内附两种内存修改器,推荐使用ProcessLook2,全中文,同时操作步骤简洁(这个也有图片指导,帮助你完成注册)。 其它,如果你不放心使用破解版本,那么你可以下载我上传的:易表.电脑报 版。这个是官方的注册版本(这两个版本可以互相打开)。地址http://download.csdn.net/user/vic99love
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值