【NOIP2016提高A组模拟7.15】计数 题解+代码

55 篇文章 0 订阅
44 篇文章 0 订阅

Description

这里写图片描述

Input

N与K(n<=1800,k<=10)

Output

答案

Sample Input

2 10

Sample Output

90

Solution

很显然的数位DP。
f[1..1800][0..1]表示好就行了。
注意高精度,其实这题算是高精度模板

Code

type arr=array[0..1000] of longint;
var
    f:array[0..1801,0..1] of arr;
    i,n,k:longint;
    mo:longint=1000000;
function cheng(a:arr;b:longint):arr;
var
    i:longint;
    c:arr;
begin
    c[0]:=0;c[1]:=0;
    for i:=1 to a[0] do
    begin
        a[i]:=c[i]+a[i]*b;c[i+1]:=0;
        if(a[i]>=mo)then begin c[i+1]:=a[i] div mo;a[i]:=a[i]mod mo;end;
    end;
    a[i+1]:=c[i+1];if(a[a[0]+1]>0) then inc(a[0]);exit(a);
end;
function jia(a,b:arr):arr;
var
    i:longint;
    c:arr;
begin
    fillchar(c,sizeof(c),0);
    if a[0]>b[0] then c[0]:=a[0] else c[0]:=b[0];
    for i:=1 to c[0] do
    begin
        c[i]:=a[i]+b[i]+c[i];
        if c[i]>=mo then begin c[i+1]:=c[i+1]+c[i]div mo;c[i]:=c[i] mod mo;end;
    end;
    if c[c[0]+1]>0 then inc(c[0]);exit(c);
end;
procedure printf(a:arr);
var
    i,j:longint;
    s:ansistring;
begin
    write(a[a[0]]);
    for i:=a[0]-1 downto 1 do
    begin
        str(a[i],s);
        for j:=length(s)+1 to 6 do write('0');
        write(a[i]);
    end;
    writeln;
end;
begin
    read(n,k);
    if n=0 then begin writeln(0);exit;end;
    f[0,0][0]:=1;f[0,0][1]:=1;
    for i:=1 to n do
    begin
        f[i,0]:=f[i-1,1];
        f[i,1]:=jia(cheng(f[i-1,0],k-1),cheng(f[i-1,1],k-1));
    end;
    printf(jia(f[n,0],f[n,1]));
end.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值