牛客練習賽53 A 超越學姐愛字串

2022-04-29 19:48:11 字數 619 閱讀 4211

/* 找規律(碰運氣)

n:1 = 2

n:2 = 3

n:3 = 5

n:4 = 8

...dp解法(參考牛客題解)

dp[i][0]:長度為 i, 字元最後乙個字元為'c'的情況數

dp[i][1]:長度為 i, 字元最後乙個字元為'y'的情況數

則有:dp[i + 1][0] = dp[i][1]; 即每個以'p'結尾的字串都可以加個'c'(保證不會有'c'連續)

dp[i + 1][1] = dp[i][1] + dp[i][0]; 'p'的限制沒'c'大,所以在任何字串後面加'p'都可

*/#include#includeusing namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

const int inf = 100000;

int n;

//ll num[100005];

ll dp[100005][2];

//void init()

//}void workindp()

}int main()

return 0;

}

牛客練習賽53 A(簡單dp)

超越學姐非常喜歡自己的名字,以至於英文本母她只喜歡 c 和 y 因此超越學姐喜歡只含有 c 和 y 的字串,且字串中不能出現兩個連續的 c 請你求出有多少種長度為n的字串是超越學姐喜歡的字串。答案對1e9 7取模。輸入乙個整數n。1 n 100000輸出乙個整數表示答案。示例1 複製3複製 5cyy...

牛客練習賽53 ABC

a 簡單dp include define ll long long using namespace std const ll mod 1e9 7 ll d 1000000 2 ll n intmain cout d n 1 d n 0 mod return0 b 分塊 include define...

牛客練習賽53 B, C, E 題解

b 美味果凍 更換一下列舉順序得到 容易發現 i 為 j,2j 2j,3j t 1 j,t j 時後面向下取整的結果是一樣的,分塊計算即可,j 次冪通過 j 1 次冪 o 1 得到,時間複雜度為 o nlogn include using namespace std typedef long lon...