题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1422
解题报告:DP题,要使旅行的城市最多,关键是要选出一个城市作为开始,以这个城市作为开始的城市时,能使拥有的钱能旅行的城市最多,我的做法是把前n-1个城市添加到n个城市的数组后面,这样就不用考虑环的问题了,
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std; int w[],l[]; int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i = ;i<n;++i)
scanf("%d%d",&w[i],&l[i]);
for(int i = ;i<n-;++i)
w[i+n] = w[i],l[i+n] = l[i];
int temp = ,tot = ,flag = ,M = ;
for(int i = ;i<*n-;++i)
{
if(temp + w[i] - l[i] >= )
{
tot ++;
temp = temp + w[i] - l[i];
}
else
{
if(tot <= n)
M = max(tot,M);
else
{
M = n;
break;
}
temp = ;
tot = ;
}
}
if(tot <= n)
M = max(tot,M);
else M = n;
printf("%d\n",M);
}
return ;
}