暴力算法为什么会RE?我还打算拿部分分结果爆零了
查看原帖
暴力算法为什么会RE?我还打算拿部分分结果爆零了
261932
qpdk777楼主2020/4/26 20:29

真的是纯暴力,可是为什么会RE?

#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long int
using namespace std;

ll n,ans,a[1000010],s[1000010];
ll dp[1010][1010],mapx[1010][1010];
int flag,cnt;

int main(){
	ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
	freopen("sequence.in","r",stdin);
	freopen("sequence.out","w",stdout);
	cin>>n;
	for(int i = 1; i <= n; ++i){
		cin>>a[i];
		dp[i][i] = 1;
		if(!s[a[i]]){
			s[a[i]] = ++cnt;
			a[i] = cnt;
		}
		else
			a[i] = s[a[i]];
		mapx[i][a[i]] = 1;
	}
	for(int i = 1; i <= n; ++i)
		for(int j = i-1; j >= 1; --j){
			flag = 1;
			if(mapx[i][a[j]])
				flag = 0;
			else
				mapx[i][a[j]] = 1;
			dp[j][i] = dp[j+1][i]+flag;
			dp[j][i] %= 1000000007;
		}
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= i; ++j){
			ans += (dp[j][i]*dp[j][i])%1000000007;
			ans %= 1000000007;
		}
	cout<<ans<<endl;
	
	return 0;
}
2020/4/26 20:29
加载中...