P1481 魔族密码 (LIS)
生活随笔
收集整理的這篇文章主要介紹了
P1481 魔族密码 (LIS)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題的連接:https://www.luogu.org/problemnew/show/P1481
簡單思路:
就是LIS,最長上升子序列,當(dāng)然把條件改一下,從模板里的A[ i ]> A[ j ]變成ss[ i ].find(ss[ j ])==0;即可。好好理解最長上升子序列。是不是和題目中的最長連續(xù)單詞呢?(自己瞎叫的名字)
ac代碼:
#include<iostream> #include<string> using namespace std; #define max(a, b) (a)>(b)?(a):(b) string ss[2001]; int dp[2001]; int main() {int n;cin >> n;for (int i = 0; i < n; ++i)cin >> ss[i];int ans = 0;for (int i = 0; i < n; ++i){dp[i] = 1;for (int j = 0; j < i;++j)if (ss[i].find(ss[j]) == 0) dp[i] = max(dp[j] + 1, dp[i]);ans = max(ans, dp[i]);}cout << ans << endl; }?
轉(zhuǎn)載于:https://www.cnblogs.com/ALINGMAOMAO/p/9490251.html
總結(jié)
以上是生活随笔為你收集整理的P1481 魔族密码 (LIS)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jdbc连接sqlserver,mysq
- 下一篇: go struct结构