hihoCoder #1444 : Push Button II ( dp

题目链接:
https://hihocoder.com/problemset/problem/1444

题意:

很容易发现这个就是一个线性的 d p dp dp
考虑一下 d p [ i ] [ j ] dp[i][j] dp[i][j]表示长度 i i i的分为 j j j大小的块的大学长度
明显我们可以发现 状态 d p [ i ] [ j ] dp[i][j] dp[i][j]的状态可以由 d p [ i ] [ j − 1 ] dp[i][j-1] dp[i][j1] d p [ i − 1 ] [ j − 1 ] ] dp[i-1][j-1]] dp[i1][j1]]推出来 ,所以状态转移方程为
d p [ i ] [ j ] = d p [ i − 1 ] [ j − 1 ] ∗ j + d p [ i ] [ j − 1 ] ∗ j dp[i][j]=dp[i-1][j-1]*j+dp[i][j-1]*j dp[i][j]=dp[i1][j1]j+dp[i][j1]j

//    Created by Yishui
//    Time on 2018/10/
//    E-mail: Yishui_wyb@outlook

/*---------------------------------*/

#include 
using namespace std;

#define cpp_io() {ios::sync_with_stdio(false); cin.tie(NULL);}
#define rep(i,a,n) for (int i=a;i
#define repp(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define CLR(a,b) memset(a,(b),sizeof(a))
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ls o<<1
#define rs o<<1|1


typedef long long ll;
typedef vector<int> VI;
const int MAXN = (int)1e3+10;
const int INF = 0x3f3f3f3f;
const int mod = (int)1e9+7;

void F() {
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}

ll dp[MAXN][MAXN];

int main() {
    int n; cin>>n;
    dp[0][0]=1;
    repp(i,1,n) repp(j,1,n) {
            dp[i][j] = dp[i-1][j-1]*j*1LL+dp[i-1][j]*j*1LL;dp[i][j]%=mod;
    }
        
    ll ans=0;
    repp(i,1,n) ans=(ans+dp[n][i])%mod;
    cout<<ans<<"\n";
    return 0;
}

你可能感兴趣的:(online,judge,Others,动态规划,就是)