URAL 1203 Scientific Conference dp练习

Functioning of a scientific conference is usually divided into several simultaneous sections. For example, there may be a section on parallel computing, a section on visualization, a section on data compression, and so on.
Obviously, simultaneous work of several sections is necessary in order to reduce the time for scientific program of the conference and to have more time for the banquet, tea-drinking, and informal discussions. However, it is possible that interesting reports are given simultaneously at different sections.

A participant has written out the time-table of all the reports which are interesting for him. He asks you to determine the maximal number of reports he will be able to attend.


题目好多词都看不懂 我是英语渣渣 , 于是求助与愚蠢的翻译软件。 果然翻译软件是愚蠢的。

然而,通过努力我自己看懂了。

对于每一个时间,当前时间的最大可以参加的会议数 取前一个时间的值 和当前时间结束的最后一个会议的 开始时间的前一个时间的会议数+1 ,取两者间的大值。 嗯, 果然我也没看懂我在说什 , 上方程

                                          dp[i] =  max( dp[i-1] , dp[ t[i] - 1] + 1)

如果在 第i时刻没参加会议或会议还没结束 那么参加的会议数应该和前一时刻相等。 如果该时刻有个会议结束了 ,那么这个时刻的会议数应该是会议开始前的 前一时刻会议数+1。

#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 30100
int dp[N];
int t[N];
int n;
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i = 0; i <= 30000;i++) {  t[i] = 0; }
        int ts,te,maxx = 0;
        for(int i = 1; i <= n; i++)
        {
            scanf("%d%d",&ts,&te);
            t[te] = max(t[te],ts);
            maxx = max(maxx,te);
        }
        dp[0] = 0;
        for(int i = 1; i <= maxx; i++)
        {
           dp[i] = dp[i-1];
           if(t[i] != 0)
            dp[i] = max(dp[i],dp[t[i]-1]+1);
        }
        printf("%d\n",dp[maxx]);
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值