您的位置:首页 > Web前端

URAL 1203 Scientific Conference dp练习

2015-08-27 11:09 253 查看
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
;
int t
;
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: