题目描述 Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no more 25 of the characters 'a'..'z'. Their cowmunication system, based on mooing, is not very accurate; sometimes they hear words that do not make any…
P2875 [USACO07FEB]牛的词汇The Cow Lexicon 三维dp 它慢,但它好写. 直接根据题意设三个状态: $f[i][j][k]$表示主串扫到第$i$个字母,匹配到第$j$个单词的第$k$位可以留下的最多字符数 当该位不选时,就传递上一位的数据$f[i][j][k]=f[i-1][j][k]$ 当该位可以匹配时: $if(a[i]==b[j][k]\&\&f[i-1][j][k-1])$$f[i][j][k]=max(f[i][j][k],f[i-1][j][k-1…
P2875 [USACO07FEB]牛的词汇The Cow Lexicon 题目描述 Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no more 25 of the characters 'a'..'z'. Their cowmunication system, based on mooing, is not very accurate; sometime…
https://daniu.luogu.org/problemnew/show/P2875 dp[i]表示前i-1个字符,最少删除多少个 枚举位置i, 如果打算从i开始匹配, 枚举单词j,计算从i开始往后,匹配完单词j的位置pos,删除的字母个数sum dp[pos]=min(dp[i]+sum) 如果不用i匹配,dp[i+1]=min(dp[i]) #include<cstdio> #include<cstring> #include<iostream> using…
传送门 f[i] 表示前 i 个字符去掉多少个 的最优解 直接暴力DP ——代码 #include <cstdio> #include <cstring> #include <iostream> ]; ], a[][]; inline int read() { , f = ; char ch = getchar(); ; ) + (x << ) + ch - '; return x * f; } inline int min(int x, int y) {…
题目链接:https://www.luogu.org/problemnew/show/P2863 求强连通分量大小>自己单个点的 #include <stack> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 100000 + 10; struct edge…
题目描述 The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their finest gowns, complete with corsages and new shoes. They know that tonight they will each try to perform the Round Dance. Only cows can perform the Round D…
题目传送门 这个题还是个缩点的板子题...... 答案就是size大于1的强连通分量的个数 加一个size来统计就好了 #include <iostream> #include <cstdlib> #include <cstdio> using namespace std; const int N=1e5+5; const int M=5e5+5; struct edge{ int to,next; }e[M]; int n,m,dfn[N],low[N],cnt,he…
题目链接 赤裸裸的板子,就加一个特判就行.直接上代码 #include<stdio.h> #include<algorithm> #include<iostream> using namespace std; ];//记录入没入栈. ];//特判*1,是强连通分量就直接过了. ]; ];//手写栈. void push(int x)//手写栈ing. { ins[x]=true; stack[++top]=x; return ; } void pop() { ins[s…
[题解] Luogu P5446 [THUPC2018]绿绿和串串 ·题目大意 定义一个翻转操作\(f(S_n)\),表示对于一个字符串\(S_n\), 有\(f(S)= \{S_1,S_2,...,S_{n-1},S_n,S_{n-1},...S_2,S_1 \}\). 现在给定一个长度为\(n\)的字符串\(S^{'}\)表示原字符串\(S\)经过若干次(可能为0)旋转之后的一个前缀, 求原来字符串可能的长度\(l\). 显然当\(l > n\)时一定可行,所以只需要输出所有的\(l\leq…