UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#210947#2069. 组合技drdilyor201023ms1196kbC++111.6kb2024-08-08 12:21:512024-08-08 12:41:47

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
void ts(){cout<<"IAKIOI\n";}
inline int read(){
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}
const int mod=998244353;
struct mint{
    int x;mint(int o=0){x=o;}mint&operator+=(mint a){return(x+=a.x)%=mod,*this;}mint&operator-=(mint a){return(x+=mod-a.x)%=mod,*this;}
    mint&operator*=(mint a){return(x=1ll*x*a.x%mod),*this;}mint&operator^=( int b){mint a=*this;x=1;while(b)(b&1)&&(*this*=a,1),a*=a,b>>=1;return*this;}
    mint&operator/=(mint a){return*this*=(a^=mod-2);}friend mint operator+(mint a,mint b){return a+=b;}friend mint operator-(mint a,mint b){return a-=b;}
    friend mint operator*(mint a,mint b){return a*=b;}friend mint operator/(mint a,mint b){return a/=b;}friend mint operator^(mint a,int b){return a^=b;}
    mint operator-(){return 0-*this;}bool operator==(const mint b)const{return x==b.x;}
};
int m,n;
char s[1005][1005];
int d[1005];
int res;
char p[1005];
void dfs(int x){
	if(x==m+1){
		int cnt=0;
		for(int i=1;i<=n;i++){
			int len=strlen(s[i]+1);
			for(int j=1;j+len-1<=m;j++){
				bool ok=1;
				for(int k=j;k<j+len;k++)ok&=(p[k]==s[i][k-j+1]);
				if(ok){cnt+=d[i];}
			}
		}
		res=max(res,cnt);
		return;
	}
	p[x]='A';dfs(x+1);
	p[x]='B';dfs(x+1);
	p[x]='X';dfs(x+1);
	p[x]='Y';dfs(x+1);
}
void work(){
	dfs(1);
	printf("%lld\n",res);
}
signed main(){
	m=read(),n=read();
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
		d[i]=read();
	}
	if(n<=10&&m<=10){work();return 0;}
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 333ms
memory: 1192kb

input:

10 10
BA 476
BA 463
AAABAAX 2044
BBAXXA 934
B 128
BAXBB 886
AXB 784
AXABX 917
XXXABBA 905
XB 343

output:

7483

result:

ok "7483"

Test #2:

score: 0
Accepted
time: 349ms
memory: 1196kb

input:

10 10
XAA 427
AAAXXA 1790
XAX 817
XAAXA 1298
AXA 761
A 101
AXXXA 980
AAXA 859
XAA 741
AAXXAAA 868

output:

10808

result:

ok "10808"

Test #3:

score: 0
Accepted
time: 341ms
memory: 1192kb

input:

10 10
AXXX 614
AX 511
BB 229
YBA 875
XBA 858
YXY 510
BBBAB 644
XBYB 819
YBBABXBXY 1119
YYXAB 699

output:

4124

result:

ok "4124"

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 1156kb

input:

1000 1
BABBXXBXBBABBXBBXXAAAAXBXXBXXXXXAAAAAAXXABBBB 13224

output:


result:

wrong answer Unexpected EOF in the participants output

Subtask #3:

score: 0
Skipped

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 0ms
memory: 1160kb

input:

1000 10
BAAABX 1583
AXAXXXA 1407
BAAXAXXXXXX 3235
XBBBAAABBA 2201
BBBAAX 702
BBXB 500
BXAXX 845
XBXB...

output:


result:

wrong answer Unexpected EOF in the participants output

Subtask #5:

score: 0
Skipped