codefoces 1400B RPG Protagonist
作者:互联网
https://codeforces.com/contest/1400/problem/D
i<j<k<l
假设x = list【j】
y = list【k】
可以枚举j和k,0----j-1有a个y,k+1 -- n有b个x,ans+=a*b枚举就好了
具体看代码
#include<iostream> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; const int maxn = 3e3+11; ll dp[maxn][maxn]; int list[maxn]; int main(){ int t; cin>>t; while(t--){ int n; cin>>n; for(int i=1;i<=n;i++){ cin>>list[i]; for(int j=1;j<=n;j++){ dp[i][j] = dp[i-1][j]; } dp[i][list[i]]++; } ll ans = 0; for(int j = 2;j<=n;j++){ for(int k=j+1;k<=n-1;k++){ int x = list[j]; int y = list[k]; ans += (dp[j-1][y])*(dp[n][x] - dp[k][x]); } } cout<<ans<<endl; } return 0; }
标签:codefoces,ll,list,long,int,Protagonist,maxn,1400B,include 来源: https://www.cnblogs.com/lesning/p/13610772.html