[题目链接]

         https://www.luogu.org/problemnew/show/P1311

[算法]

        递推即可,时间复杂度 :O(NK)

[代码]

        

#include<bits/stdc++.h>
using namespace std;
#define MAXN 200010
#define MAXK 55

pair<int,int> a[MAXN];
int s[MAXN][MAXK];

template <typename T> inline void read(T &x)
{
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; 
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

int main() 
{
        
        int n,k,p;
        read(n); read(k); read(p);
        int ans = 0;
        for (int i = 1; i <= n; i++)
        {
                read(a[i].first);
                read(a[i].second);
        }
        int last = 0;
        for (int i = 1; i <= n; i++)
        {
                if (a[i].second <= p) last = i;
                if (last == i) ans += s[i - 1][a[i].first];
                else if (last != 0) ans += s[last][a[i].first];
                for (int j = 0; j < k; j++) s[i][j] = s[i - 1][j];
                s[i][a[i].first]++;        
        }
        printf("%d\n",ans);
        
        return 0;
    
}

 

相关文章:

  • 2021-08-04
  • 2018-05-23
  • 2021-10-27
  • 2021-08-15
猜你喜欢
  • 2021-08-19
  • 2022-12-23
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2021-08-29
相关资源
相似解决方案