ZOJ Problem Set - 2972
来源:互联网 发布:mac qq可以同时登陆 编辑:程序博客网 时间:2024/04/28 10:48
Time Limit: 1 Second Memory Limit: 32768 KB
In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of China and Beijing Olympics is to be a festival for people all over the world as well.
Liu Xiang is one of the famous Olympic athletes in China. In 2002 Liu broke Renaldo Nehemiah's 24-year-old world junior record for the 110m hurdles. At the 2004 Athens Olympics Games, he won the gold medal in the end. Although he was not considered as a favorite for the gold, in the final, Liu's technique was nearly perfect as he barely touched the sixth hurdle and cleared all of the others cleanly. He powered to a victory of almost three meters. In doing so, he tied the 11-year-old world record of 12.91 seconds. Liu was the first Chinese man to win an Olympic gold medal in track and field. Only 21 years old at the time of his victory, Liu vowed to defend his title when the Olympics come to Beijing in 2008.
In the 110m hurdle competition, the track was divided into N parts by the hurdle. In each part, the player has to run in the same speed; otherwise he may hit the hurdle. In fact, there are 3 modes to choose in each part for an athlete -- Fast Mode, Normal Mode and Slow Mode. Fast Mode costs the player T1 time to pass the part. However, he cannot always use this mode in all parts, because he needs to consume F1 force at the same time. If he doesn't have enough force, he cannot run in the part at the Fast Mode. Normal Mode costs the player T2 time for the part. And at this mode, the player's force will remain unchanged. Slow Mode costs the player T3 time to pass the part. Meanwhile, the player will earn F2 force as compensation. The maximal force of a player is M. If he already has M force, he cannot earn any more force. At the beginning of the competition, the player has the maximal force.
The input of this problem is detail data for Liu Xiang. Your task is to help him to choose proper mode in each part to finish the competition in the shortest time.
Input
Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. And it will be followed by T consecutive test cases.
Each test case begins with two positive integers N and M. And following N lines denote the data for the N parts. Each line has five positive integers T1 T2 T3 F1 F2. All the integers in this problem are less than or equal to 110.
Output
Results should be directed to standard output. The output of each test case should be a single integer in one line, which is the shortest time that Liu Xiang can finish the competition.
Sample Input
21 101 2 3 10 104 101 2 3 10 101 10 10 10 101 1 2 10 101 10 10 10 10
Sample Output
16
Hint
For the second sample test case, Liu Xiang should run with the sequence of Normal Mode, Fast Mode, Slow Mode and Fast Mode.
#include<stdio.h>
int i,j,m,n,count1,t1,t2,t3,dec,inc;
int f[111][111];
int min(int a,int b)
{
if(a<b) return a;
return b;
}
int main()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
scanf("%d",&count1);
while(count1--)
{
scanf("%d%d",&n,&m);
for(i=0;i<=n;i++)
for(j=0;j<=m;j++)
if(i==0)
f[i][j]=0;
else
f[i][j]=1<<25;
//f[0][m]=0;
for(i=1;i<=n;i++)
{
scanf("%d%d%d%d%d",&t1,&t2,&t3,&dec,&inc);
for(j=0;j<=m;j++)
{
if(j>=dec)
f[i][j-dec]=min(f[i][j-dec],f[i-1][j]+t1);
f[i][j]=min(f[i][j],f[i-1][j]+t2);
if(j+inc<=m)
f[i][j+inc]=min(f[i][j+inc],f[i-1][j]+t3);
else
f[i][m]=min(f[i][m],f[i-1][j]+t3);
}
}
int max=1<<25;
for(i=0;i<=m;i++)
if(max>f[n][i]) max=f[n][i];
printf("%d/n",max);
}
return 0;
}
- ZOJ Problem Set - 2972
- ZOJ Problem Set - 2060
- ZOJ Problem Set - 1037
- ZOJ Problem Set - 1048
- ZOJ Problem Set - 1049
- ZOJ Problem Set - 1051
- ZOJ Problem Set - 1067
- ZOJ Problem Set - 1115
- ZOJ Problem Set - 1151
- ZOJ Problem Set - 1205
- ZOJ Problem Set - 1025
- ZOJ Problem Set - 1029
- ZOJ Problem Set - 1076
- ZOJ Problem Set - 1117
- ZOJ Problem Set - 1041
- ZOJ Problem Set - 1004
- ZOJ Problem Set - 1005
- ZOJ Problem Set - 1016
- 解铃还须系铃人
- 链表
- 命令行管理系统服务工具 sc.exe
- 路由器后面的内网计算机如何向外网提供网络服务
- 浅析C++中的this指针
- ZOJ Problem Set - 2972
- UNIX/LINUX 平台可执行文件格式分析
- redhad enterprise 5 iptables 端口映射
- 获得两个字符串中间的字符串
- CentOS中安装subversion,并使用svn+ssh访问
- 1028: Dividing Up
- 写文件UNICODE相关
- C程序的编译过程
- PHP 多维数组删除某字段或某几个字段