QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#761685#7006. Rikka with Subsequenceseggegg185AC ✓826ms104296kbC++141.2kb2024-11-19 08:50:452024-11-19 08:50:46

Judging History

你现在查看的是最新测评结果

  • [2024-11-19 08:50:46]
  • 评测
  • 测评结果:AC
  • 用时:826ms
  • 内存:104296kb
  • [2024-11-19 08:50:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int n,dp[205][205][205],g[205][205][205],h[205][205][205],a[205]; char m[205][205];
int main() {
	cin.tie(0)->sync_with_stdio(false);
	int T; scanf("%d",&T); while(T--) { //I guess the sol is (and is only) counting 3 subseqs, use sth like prefix to get better.
		scanf("%d",&n); for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
		for(int i = 1; i <= n; i++) scanf("%s",m[i]+1);
		for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) for(int k = 1; k <= n; k++) {
			dp[i][j][k] = g[i][j][k] = h[i][j][k] = 0;
			if(a[i] == a[j] && a[j] == a[k]) dp[i][j][k] = 1;
		}
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				for(int k = 1; k <= n; k++) {
					if(m[a[j]][a[i]] == '1') (g[i][j][k] += dp[i-1][j][k]) %= mod; //extend once
					if(a[i] == a[j]) (h[i][j][k] += g[i][j-1][k]) %= mod; //extend twice
					if(a[i] == a[k]) (dp[i][j][k] += h[i][j][k-1]) %= mod;
					(dp[i][j][k] += dp[i-1][j][k]) %= mod;
					(g[i][j][k] += g[i][j-1][k]) %= mod;
					(h[i][j][k] += h[i][j][k-1]) %= mod;
				}
			}	
		}
		int ans = 0; for(int j = 1; j <= n; j++) for(int k = 1; k <= n; k++) (ans += dp[n][j][k]) %= mod;
		printf("%d\n",ans);
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 10100kb

input:

1
4
1 2 1 2
1111
1111
1111
1111

output:

51

result:

ok single line: '51'

Test #2:

score: 0
Accepted
time: 826ms
memory: 104296kb

input:

20
195
4 5 4 3 2 4 3 5 1 5 4 3 4 3 1 5 4 4 5 2 2 2 2 4 1 5 3 4 1 1 1 2 1 1 5 5 4 5 4 5 5 4 5 2 1 2 5 4 5 1 1 3 1 2 2 3 3 5 2 3 3 1 4 4 2 4 2 4 3 4 1 1 1 4 3 5 1 1 3 2 2 5 1 3 1 5 1 5 5 3 5 3 3 2 5 1 3 2 4 1 5 5 1 3 3 2 4 2 3 3 3 4 1 3 3 3 5 5 1 1 4 2 5 1 2 5 4 3 5 1 5 5 5 4 2 2 5 3 2 3 4 1 3 2 1 5 3...

output:

806298135
541285042
48173297
222851978
875793336
100057791
156057874
129923599
551277543
874547790
544405786
653241411
521317929
370918040
803940504
969296122
806596012
469227084
338962879
194278629

result:

ok 20 lines