| ||||||||||
| 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 | |||||||||
Re:极其简单的DP 就是 WA不段 郁闷啊!!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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator