zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

    寻找真正的热爱
  • 相关阅读:
    正则表达式
    Ajax跨域问题---jsonp
    Ajax
    字符串总结
    js 字符串加密
    jsDate()
    HDU 5430 Reflect
    HDU 5429 Geometric Progression
    HDU 5428 The Factor
    POJ 2485 Highways
  • 原文地址:https://www.cnblogs.com/lesning/p/13610772.html
Copyright © 2011-2022 走看看