Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- using namespace std;
- typedef struct{
- int start;
- int end;
- }t_route;
- int compare(t_route a, t_route b){
- return a.start < b.start;
- }
- t_route A[4000];
- int N,M;
- int main(){
- int i,j,x,y,num_t;
- scanf("%d%d",&N,&M);
- for(i = 0;i < M;i ++){
- scanf("%d%d",&A[i].start,&A[i].end);
- }
- sort(A,A+M,compare);
- int dp[M+5] = {0};
- dp[0] = 1;
- int ans = 1;
- for(i = 1;i < M; i++){
- for(j = 0; j < i; j++){
- if(A[i].start > A[j].start && A[i].start <= A[j].end){
- dp[i] = max(dp[i],dp[j]+1);
- ans = max(ans,dp[i]);
- }
- }
- }
- printf("%d",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment