[HNOI2006]花仙子的魔法

囧。。其实这玩意等价于分空间的问题,设维数为d魔法n次为dp(d,n)
则dp(d,n)=dp(d-1,n-1)+dp(d,n-1)
dp(1,i)=2*i
dp(i,0)=1
。。。我一开始是解了个方程。因为我发现结果是d次函数,并且前d+1个值都是2的幂,
所以可以解出系数然后计算囧。。写了半天。真是沙茶到家了555
HNOI2006A了5道。。剩下的就不会做了。。
Code:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
using namespace std;
const int inf=~0U>>1;
const int maxn=100+1,maxd=16;
int n,d;
long long dp[maxd][maxn]={0};
int main()
{
cin>>n>>d;
rep(i,n+1)dp[1][i]=i*2;dp[1][0]=1;
for(int i=2;i<=d;i++)
{
dp[i][0]=1;
for(int j=1;j<=n;j++)
dp[i][j]=dp[i][j-1]+dp[i-1][j-1];
}
cout<<dp[d][n]<<endl;
}

2 thoughts on “[HNOI2006]花仙子的魔法

Leave a Reply

Your email address will not be published. Required fields are marked *