Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:极其简单的DP 就是 WA不段 郁闷啊!!

Posted by lizimeng at 2016-03-26 02:39:32 on Problem 1609
In Reply To:极其简单的DP 就是 WA不段 郁闷啊!! Posted by:hokey at 2008-03-31 22:10:41
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <algorithm>
> using namespace std;
> #define MAX 10101
> 
> int dp[MAX];		
> struct  tt{
> 	int l;
> 	int r;
> }block[MAX];
> 
> int cmp(void const *a, void const *b)
> {
> 	if(((struct tt*)a)->l == ((struct tt*)b)->l)
> 		return ((struct tt*)a)->r - ((struct tt*)b)->r;
> 	else
> 		return ((struct tt*)a)->l - ((struct tt*)b)->l;
> }
> 
> int main()
> {
> 	int i, n;
> //	freopen("d.txt","r",stdin);
> 	while(scanf("%d", &n) && n)
> 	{
> 		memset(dp, 0 ,sizeof(dp));
> 		for(i=0; i<n; i++)	scanf("%d%d", &block[i].l, &block[i].r);
> 		qsort(block, n,sizeof(block[0]), cmp);			//  从小到大排
> 		dp[0] = 1;
> 		for(i=1; i<n; i++)
> 			if(block[i].r >= block[i-1].r)
> 				dp[i] = dp[i-1] + 1;
> 			else
> 				dp[i] = dp[i-1];
> 		printf("%d\n", dp[n-1]);
> 	}
> 	putchar('*');
> 	return 1;
> }
你这想的也太浅了吧。我已开始也什么想,但是很快就否决了。
给你一组数据:
5
1 100
2 1
3 1
4 1

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator