首页 > 代码库 > BestCoder Round #24 b
BestCoder Round #24 b
#include <iostream> #include <fstream> #include <vector> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; #ifdef DEBUG ifstream in; ofstream out; #endif #ifdef DEBUG #define CIN in #define COUT out #else #define CIN cin #define COUT cout #endif #define MAXN 105 #define MOD 1000000007 #define CLR(vec) memset(vec, 0, sizeof(vec)) typedef long long int ll; int n; int record[MAXN]; /*0: sit after the prev one , 1 sit before prev one*/ int dp[2][MAXN][MAXN]; static inline void check_mod(ll &num){ if(num > MOD) num %= MOD; } int main(void) { #ifdef DEBUG string buffer; CIN.open("in", ios::in); COUT.open("out", ios::out); while(getline(CIN, buffer)) COUT << buffer << "\n"; COUT << "Out Put" << "\n"; CIN.close(); CIN.open("in", ios::in); #endif while(CIN >> n){ CLR(dp); CLR(record); int pp, p, curr; ll tmp; for(int i = 1; i <= n; i++){ pp = p; p = curr; CIN >> curr; if(i >= 3 && pp != curr) record[i] = 1; } dp[0][1][1] = 1; for(int i = 2; i <= n; i++) for(int j = 1; j <= i; j++){ if(record[i]){ tmp = 0; for(int k = j; k <= i - 1; k++){ tmp+= dp[1][i - 1][k]; check_mod(tmp); } dp[1][i][j] = tmp; tmp = 0; for(int k = 1; k <= j - 1; k++){ tmp += dp[0][i - 1][k] + dp[1][i - 1][k]; check_mod(tmp); } dp[0][i][j] = tmp; }else{ tmp = 0; for(int k = j; k <= i - 1 ; k++){ tmp += dp[0][i - 1][k] + dp[1][i - 1][k]; check_mod(tmp); } dp[1][i][j] = tmp; tmp = 0; for(int k = 1; k <= j - 1; k++){ tmp += dp[0][i - 1][k] + dp[1][i - 1][k]; check_mod(tmp); } dp[0][i][j] = tmp; } } ll ans = 0; for(int i = 1; i <= n; i++){ ans += dp[0][n][i] + dp[1][n][i]; check_mod(ans); } COUT << ans << "\n"; } return 0; }
BestCoder Round #24 b
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。