zoukankan      html  css  js  c++  java
  • [NOIP 2011] 选择客栈

    [题目链接]

             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
    ",ans);
            
            return 0;
        
    }
  • 相关阅读:
    10.28作业
    10.27作业
    10.26作业
    10.22作业
    10.20作业
    10.19作业
    10.16作业
    10.15作业
    10.14作业
    10.13作业
  • 原文地址:https://www.cnblogs.com/evenbao/p/9608544.html
Copyright © 2011-2022 走看看