概述
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<bitset>
#include<map>
//#include<regex>
#include<cstdio>
#include <iomanip>
#include<unordered_map>
#pragma GCC diagnostic error "-std=c++11"
#pragma GCC optimize("-fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,-falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2",3)
#pragma GCC target("avx","sse2")
#define up(i,a,b)
for(int i=a;i<b;i++)
#define dw(i,a,b)
for(int i=a;i>b;i--)
#define upd(i,a,b) for(int i=a;i<=b;i++)
#define dwd(i,a,b) for(int i=a;i>=b;i--)
//#define local
typedef long long ll;
typedef unsigned long long ull;
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
ll read()
{
char ch = getchar(); ll x = 0, f = 1;
while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * f;
}
typedef pair<int, int> pir;
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lrt root<<1
#define rrt root<<1|1
const int mod = 1e9 + 7;
int T, n;
const int N = 220;
int a[N];
char grp[N][N];
ll sum[N][N], dp[N][N];
inline void add(ll &x, ll y) {
x += y;
if (x >= mod)x -= mod;
}
inline void sub(ll &x, ll y) {
x -= y;
if (x < 0)x += mod;
}
int main() {
T = read();
while (T--) {
n = read();
upd(i, 1, n) {
a[i] = read();
}
upd(i, 1, n) {
scanf("%s", grp[i] + 1);
}
memset(dp, 0, sizeof(dp));
memset(sum, 0, sizeof(sum));
ll ans = 0;
upd(i, 1, n) {
upd(j, 1, n) {
upd(k, 1, n) {
sum[j][k] = (grp[a[j]][a[i]] == '1' ? sum[j][k] = dp[j][k] : 0);
add(sum[j][k], sum[j - 1][k]);
add(sum[j][k], sum[j][k - 1]);
sub(sum[j][k], sum[j - 1][k - 1]);
}
}
upd(j, 1, n) {
upd(k, 1, n) {
if (a[i] == a[j] && a[j] == a[k]) {
ll temp = 1;
add(temp, sum[j - 1][k - 1]);
add(ans, temp);
add(dp[j][k], temp);
}
}
}
// cout << ans << endl;
}
printf("%lldn", ans);
}
return 0;
}
最后
以上就是酷炫哈密瓜为你收集整理的The 2018 ICPC Asia Xuzhou Regional Contest的全部内容,希望文章能够帮你解决The 2018 ICPC Asia Xuzhou Regional Contest所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复