首页 > 代码库 > BZOJ 1197 花仙子的魔法(递推)

BZOJ 1197 花仙子的魔法(递推)

数学归纳法。

dp[i][j]=dp[i][j-1]+dp[i-1][j-1].

 

技术分享
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-3
# define MOD 100000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
    int res=0, flag=0;
    char ch;
    if((ch=getchar())==-) flag=1;
    else if(ch>=0&&ch<=9) res=ch-0;
    while((ch=getchar())>=0&&ch<=9)  res=res*10+(ch-0);
    return flag?-res:res;
}
void Out(int a) {
    if(a<0) {putchar(-); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+0);
}
const int N=10005;
//Code begin...

LL dp[20][105];

void init()
{
    FOR(i,1,100) dp[1][i]=2*i;
    FOR(i,1,15) dp[i][1]=2;
    FOR(i,2,15) FOR(j,2,100) dp[i][j]=dp[i][j-1]+dp[i-1][j-1];
}
int main ()
{
    init();
    int n, m;
    scanf("%d%d",&m,&n);
    printf("%lld\n",dp[n][m]);
    return 0;
}
View Code

 

BZOJ 1197 花仙子的魔法(递推)