Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贴Java代码。DP O(n*log n)import java.util.*; public class Main{ public static void main(String args[]){ Scanner s = new Scanner(System.in); int T = s.nextInt(); for(int t = 0; t < T; t++){ int n = s.nextInt(); stick sts[] = new stick[n]; for(int i = 0; i < n; i++){ sts[i] = new stick(); sts[i].l = s.nextInt(); sts[i].w = s.nextInt(); } Arrays.sort(sts); int dp[] = new int[n+1]; int len = 0; for(int i = 0; i < n; i++){ int l = 0, r = len; while(l <= r){ int temp = (l+r)/2; if(dp[temp] > sts[i].w){ l = temp + 1; }else { r = temp - 1; } } dp[l] = sts[i].w; if(l == len) len++; } System.out.println(len); } } } class stick implements Comparable<stick>{ int l,w; public int compareTo(stick o) { if(this.l == o.l) return this.w - o.w; else return this.l - o.l; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator