Qiuqiqiu  
不管道路多么崎岖坎坷,我永远不停下追逐梦想的脚步!

http://acm.hdu.edu.cn/showproblem.php?pid=2037

DP

先按开始时间(t.s)排序 f[i]记录看第i个节目时,最多可看的节目数

for i:=1 to n do

  for j:=1 to i-1 do

    if t[i].s>=t[j].e then f[i]:=max(f[i],f[j]+1);

View Code
 1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 const int N=110;
5 struct tv
6 {
7 int s,e;
8 }t[N];
9 int f[N];
10 int cmp(const void *a,const void *b)
11 {
12 return (*(tv*)a).s-(*(tv*)b).s;
13 }
14 int main()
15 {
16 int n,max=0;
17 while (scanf("%d",&n) && n)
18 {
19 t[0].s=t[0].e=0;
20 for (int i=1;i<=n;i++) scanf("%d%d",&t[i].s,&t[i].e);
21 qsort(t+1,n,sizeof(t[0]),cmp);
22 max=0;
23 memset(f,0,sizeof(f));
24 for (int i=1;i<=n;i++)
25 {
26 for (int j=0;j<i;j++)
27 if (t[i].s>=t[j].e)
28 f[i]>?=f[j]+1;
29 max>?=f[i];
30 }
31 printf("%d\n",max);
32 }
33 }

 

posted on 2011-11-26 12:10  Qiuqiqiu  阅读(231)  评论(0编辑  收藏  举报