Luo Valley Inn Select -1311

Title Description
Lijiang river there are n very unique inn, the inn according to their position in order from 1 to n number. Each inn are carried out in accordance with a certain kind of tone decoration (k species in total, ~ k-1 represents an integer 0), and each inn has a coffee shop, every coffee shop has its own minimum consumption.
To go along with two tourists in Lijiang tourism, they like the same tone, want to try two different inn, it was decided were living in the same two-tone inn. At night, they intend to select a coffee shop drinking coffee, the coffee shop is located in requirements (including the inn they lived) between two inn both live, and the lowest consumption of coffee shops does not exceed ppp.
They want to know how many there are in total choice of accommodation programs, to ensure that at night you can find a minimum consumption of no more than a coffee shop p yuan-together.
Input Output Format
Input Format:
total row n + 1.
The first row of three integers n, k, p, between each two integers separated by a space, respectively represent the number inn, the number of tones of the lowest and the highest value acceptable;
next n lines, i + 1-row two integers, separated by a space between, respectively, the lowest number of consumer coffee shop i inn decorated with pastel colors and ii i numbers inn.
Output formats:
an integer, the total number of alternative accommodation plan representation.

Input Sample # 1:
. 5. 3 2
0. 5
1. 3
0 2
1. 4
1. 5

Output Sample # 1:
3

DESCRIPTION
[O] Example Description
2 people to live in the same tone of the inn, all alternative accommodation include: live inn ①③, ②④, ②⑤, ④⑤, but if you choose to live, then inn 4,5, 4, 5 minimum consumption of coffee shops between the inn is 4, and the lowest consumer can withstand two is $ 3, it does not meet the requirements. Therefore, only the first three schemes optional.
[Data] range
to 100% of the data, there 2≤n≤200,000,0 <k≤50,0≤p≤100,0≤ minimum consumption ≤100.

Explanation: If the price is less than equal to p 1 hit mark, good for marking prefix and, at the same time deal with the prefix and the number of the same type, the same type and its precursor, the precursor to determine if there is between now and cafes, it the number of classes before direct precursor to the statistics, otherwise it is just a precursor, look at the code just fine

#include<iostream>
#define N 200004
using namespace std;
int a[N]={0};
int b[N]={0};
int n=0,k=0,p=0;
int f[N]={0};
int pos[N]={0};
long long dp[N]={0};
int num[N]={0};
long long ret=0;
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>k>>p;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        num[i]++;
        if(pos[a[i]]){
            f[i]=pos[a[i]];
            num[i]+=num[f[i]];
        }
        pos[a[i]]=i;
        b[i]=(b[i]<=p?1:0);
        b[i]+=b[i-1];
    }
    for(int i=1;i<=n;i++){
        if(f[i]&&b[i]-b[f[i]-1]) dp[i]+=num[f[i]];
        else dp[i]=dp[f[i]];
        ret+=dp[i];
    }
   cout<<ret<<endl;
    return 0;
}

Guess you like

Origin blog.csdn.net/mkopvec/article/details/92183099