牛客網練習賽 拖公尺的咒語

2021-08-21 20:22:06 字數 1589 閱讀 1837

托公尺沒有完成上乙個任務,準備施展黑魔法推倒 1317

黑魔法咒語被描述為乙個 長為 n 的,僅包含小寫英文本母 『a』…』i』 的字串,在托公尺所在的星球,魔法造成的每次有效傷害都是來自他的乙個子串行,對於每乙個 『a』… 『i』 的排列(共 9! 種),若作為咒語的子串行出現, 就會造成 1 的傷害

暴力

#include 

#include

using

namespace

std;

//#define int long long

char s[5000];

signed main()

else i++;

}if(t==9)

ans++;

}while(next_permutation(a,a+9));

cout

}

二分

#include

#include

#include

#include

#include

using

namespace

std;

char s[3005];

vector

v[10];

char a=;

int main()

for(int i=0;i<9;i++)

int ans=0;do}

if(!leap)

ans++;

}while(next_permutation(a,a+9));

printf("%d\n",ans);

return

0;}

預處理出下乙個位置

#include 

using

namespace

std;

const

int maxn = 3000 + 7;

char s[maxn], p[10];

int nx[maxn][30], first[30];

int main()

}int ans = 0;do}

if(flag) ans++;

}while(next_permutation(p + 1, p + 9 + 1));

printf("%d\n", ans);

return

0;}

更快的預處理:

#include 

using

namespace

std;

const

int maxn = 3000 + 7;

char s[maxn], p[10];

int nx[maxn][30], first[30], pos[30];

int main()

int ans = 0;do}

if(flag) ans++;

}while(next_permutation(p + 1, p + 9 + 1));

printf("%d\n", ans);

return

0;}

牛客練習賽23 D題 托公尺的咒語

題目大意 給出乙個字串,求 abcdefghi 的全排列中有幾個是該字串的子串行。分析 該題需注意是計算全排列的中符合條件種類,而不是個數。其次,看到字串匹配的題目會先想到kmp,但是這題要匹配的是子串行,所以不要想太複雜,用字首和加二分的方法就能判斷子串行,該方法的效率是 logm n,其中n為9...

牛客網練習賽33

tokitsukaze最近沉迷一款rpg。這個rpg一天有k分鐘,每一天從第1分鐘開始。有n種怪物,第i種怪物每天第一次出現的時間為xi分鐘,第二次出現的時間為2 xi分鐘,第三次出現的時間為3 xi分鐘.同一時刻出現的怪物種類越多,打怪獲得的經驗也越高。為了高效練級,tokitsukaze想知道在...

牛客網練習賽33

tokitsukaze最近沉迷一款rpg。這個rpg一天有k分鐘,每一天從第1分鐘開始。有n種怪物,第i種怪物每天第一次出現的時間為xi分鐘,第二次出現的時間為2 xi分鐘,第三次出現的時間為3 xi分鐘.同一時刻出現的怪物種類越多,打怪獲得的經驗也越高。為了高效練級,tokitsukaze想知道在...