codeforces 909C. Python Indentation
生活随笔
收集整理的這篇文章主要介紹了
codeforces 909C. Python Indentation
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
動態規劃的題目
狀態轉移方程參考https://www.cnblogs.com/Leohh/p/8135525.html
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #include<string> #include<vector> #define DEBUG(x) cout<<#x<<" = "<<x<<endl using namespace std; const int MAXN=5e3+10; const int MOD=1e9+7; ///第i個表達式縮進j個單位,有多少種結果 int dp[MAXN][MAXN]; char prg[MAXN]; int main() { // freopen("in.txt","r",stdin);int n;scanf("%d\n",&n);for(int i=1;i<=n ;i++ ){scanf("%c\n",&prg[i]);}dp[1][0]=1;for(int i=2;i<=n ;i++ ){///第i行縮進不超過i-1個單位if(prg[i-1]=='f'){dp[i][0]=0;for(int j=1;j<=i-1 ;j++ ){dp[i][j]=dp[i-1][j-1]%MOD;}}else {///從右往左,累計求和for(int j=i-2;j>=0 ;j-- ){dp[i][j]=(dp[i][j+1]%MOD+dp[i-1][j]%MOD)%MOD;}}}int ans=0;if(prg[n]=='s')for(int i=0;i<=n-1 ;i++ ){ans=(ans+dp[n][i])%MOD;}printf("%d\n",ans); }?
轉載于:https://www.cnblogs.com/MalcolmMeng/p/9941990.html
總結
以上是生活随笔為你收集整理的codeforces 909C. Python Indentation的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关键字restrict简介
- 下一篇: C#反射基础理解1(转)