BestCoder Round #82 (div.1) 1002 HDU 5677 dp-类似多重背包的思想

ztr loves substring

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Problem Description

ztr love reserach substring.Today ,he has n string.Now ztr want to konw,can he take out exactly k palindrome from all substring of these n string,and thrn sum of length of these k substring is L.

for example string "yjqqaq"

this string contains plalindromes:"y","j","q","a","q","qq","qaq".

so we can choose "qq" and "qaq".

Input

The first line of input contains an positive integer T(T<=10) indicating the number of test cases.

For each test case:

First line contains these positive integer N(1<=N<=100),K(1<=K<=100),L(L<=100).

The next N line,each line contains a string only contains lowercase.Guarantee even length of string won‘t more than L.

Output

For each test,Output a line.If can output "True",else output "False".

Sample Input

3

2 3 7

yjqqaq

claris

2 2 7

popoqqq

fwwf

1 3 3

aaa

Sample Output

False

True

True

dp[2][i][j] 表示当前选了i个回文子串使得长度为j的状态能否达到,而当前的状态只需要通过上一层转移即可

1：dp[now][0][0]=1

2:for(1<=i<=L)  枚举长度为i的回文子串去计算贡献

3:   for(1<=l<=L)  表示当前长度为l

4:      for(1<=j<=K) 表示当前的回文子串个数为j

5：     for(1<=k<=num[i])  枚举每个长度为i的回文子串选取的个数

6: k+j<=K && l+k*i<=L  边界条件

dp[now][k+j][l+k*i] | =dp[last][k][j]  当前的回文子串个数为k+j,长度为l+k*i的状态需要从上一层的回文子
串个数为k,长度为j抑或得到

```#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
int n,K,L;
int dp[2][110][110];
int num[110];
char s[110];
bool pd(int l,int r){
while(l<=r){
if(s[l]==s[r]){
l++;
r--;
} else return false;
}
return true;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&n,&K,&L);
mst(num,0);
for(int i=1;i<=n;i++){
scanf("%s",&s);
for(int j=0;j<strlen(s);j++){
for(int k=j;k<strlen(s);k++){
if(pd(j,k)) num[k-j+1]++;
}
}
}
int now=0,last=1;
dp[now][0][0]=1;
for(int i=1;i<=L;i++){
swap(now,last);
mst(dp[now],0);
for(int l=0;l<=L;l++){
for(int j=0;j<=K;j++){
for(int k=0;k<=num[i];k++){
if(k+j>K || l+k*i>L) continue;
dp[now][k+j][l+k*i]|=dp[last][j][l];
}
}
}
}
if(dp[now][K][L]) printf("True\n");
else printf("False\n");
}
return 0;
}
```

BestCoder Round #73 (div.2)（hdu 5630）

Rikka with Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 177    Accepted Submission(s): 161 Problem Description Yuta gives Rikka a chess board of size n×m. As we all know, on a chess boa

BestCoder Round #71 (div.2) （hdu 5620 菲波那切数列变形）

KK's Steel Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 350    Accepted Submission(s): 166 Problem Description Our lovely KK has a difficult mathematical problem:he has a N(1≤N≤1018) meters s

BestCoder Round #69 (div.2) Baby Ming and Weight lifting（hdu 5610）

Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 681    Accepted Submission(s): 280 Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(the

hdu5418 BestCoder Round #52 (div.2) Victor and World （ floyd+状压dp）

Problem Description After trying hard for many years, Victor has finally received a pilot license. To have a celebration, he intends to buy himself an airplane and fly around the world. There are n countries on the earth, which are numbered from 1 to