继续刷TYVJ上的DP!!!
CHEER UP!
距NOIP2011还一周...
/*
* tyvj-1034 nick的任务
* mike-w
* 2011-11-6
* ------------------
* 贡献WA若干,目前还未AC
* -----------------
* 偶然得知TYVJ也可以#ifdef ONLINE_JUDGE
* ---------------------
* 山重水复疑无路,柳暗花明又一村!
* ---------------------
* 原来是我的代码实现有问题==|||
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 10010
#define max(a,b) ((a)>(b)?(a):(b))
typedef struct _work
{
int start;
int dur;
}work;
work w[SIZE];
int opt[SIZE];
int N,K;
int comp(const void *a, const void *b)
{
return ((work*)a)->start - ((work*)b)->start;
}
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
#endif
int i;
scanf("%d%d",&N,&K);
for(i=0;i<K;i++)
scanf("%d%d",&(w[i].start),&(w[i].dur));
qsort(w,K,sizeof(work),comp);
opt[N]=0;
K--;
for(i=N;i>=1;i--)
{
while(K>=0 && w[K].start>i)
K--;
if(K>=0 && w[K].start==i)
while(K>=0 && w[K].start==i)
{
opt[i]=max(opt[i],opt[w[K].start+w[K].dur]);
K--;
}
else
opt[i]=opt[i+1]+1;
}
printf("%d\n",opt[1]);
return 0;
}