1153 Road games
2009 Noip National League popularity Group
time limit: 1 sspace limit: 128000 KBtitle level: Golden Gold SolvingTitle Description
Description
Xiao Xin is playing a simple computer game.
In the game there is a roundabout road, there are N robot factories on the road, and two adjacent robot factories are connected by a small section of the road. Small new start with a robot factory, in the clockwise order of the N robot factory numbered 1~n, because the road is annular, so the Nth robot factory and the 1th robot Factory is connected by a section of the road. Small new will be connected to the robot factory, the N-section of the road is also numbered as 1~n, and the section I road connected to the first robot factory and the first i+1 Robot Factory (1≤i≤n-1), nth section of the road connected to the Nth robot factory and the 1th robot factory.
During the game, every unit of time, each section of the road will appear some gold coins, the number of coins will change over time, that is, different units of time in the same section of the road on the number of coins may be different. Little new needs the help of a robot to collect gold coins on the road. The required robot must be purchased with some gold coins at the robot factory, and once purchased, the robot will walk in a clockwise direction along the roundabout, walking once per unit of time, from the current robot factory to the next adjacent robot factory, and collect all the gold coins from the passing road to a small new one. For example, Fture purchased a robot at the I (1≤i≤n) robot Factory, which starts with the I robot factory, walks clockwise on the road, walks through I on the first walk, reaches the i+1 robot factory (if I=n, the robot will reach the 1th robot Factory) and will All the gold coins on the road are collected to small new.
In the game, there can be no more than 2 or 2 robots on the roundabout, and each robot can walk a maximum of p times on the ring road. When you buy a robot, you need to set the number of times the robot will walk, and the number of trips can be any integer between 1~p. When a robot on the road disappears after a specified number of times, it must immediately buy a new robot in any robot factory and set a new number of times for the new robot.
Here are some additional instructions for the game:
1. The game starts from the start of the first time buying a robot.
2. The number of times to buy robots and set up robots is instantaneous and does not take time.
3. Robot and robot walking is a two independent process, robots can not buy robots when they walk, buy robots and set the number of robots to walk.
4. The cost of buying robots in the same robot factory is the same, but the cost of buying robots at different robotic plants is not necessarily the same.
5. Buy a robot to spend gold coins, at the end of the game and then the new collection of gold coins deducted, so in the game process small and medium-sized new not to worry because the gold is not enough to buy the robot and the game can not be carried out. Because of this, the number of coins collected may be negative after the game is over.
Now you know the number of coins per unit of time on each section of the road and the cost of buying robots at each robot factory, please tell Xiao Xin, after M unit time, after deducting the cost of buying the robot, how many gold coins can be collected by the small new one.
Enter a description
Input Description
The first line is 3 positive integers, n,m,p, meaning as described in the title.
The next n rows have m positive integers per line, separated by a space between each of the two integers, where line I describes the number of gold coins (number of 1≤ coins ≤100) that occur per unit time on the road I, i.e. the number of J (1≤j≤m) on line I, which indicates the amount of gold coins appearing on the road I in the first J unit time. Amount
The last line, with n integers, is separated by a space between each of the two integers, where number I represents the number of gold coins (1≤ gold ≤100) that are required to purchase the robot at the I Robot Factory.
Output description
Output Description
A total of 1 integers, representing the maximum number of coins a small new can collect in m units of time, after deducting the amount of gold purchased by the robot.
Sample input
Sample Input
2 3 2
1 2 3
2 3 4
1 2
Sample output
Sample Output
5
Data range and Tips
Data Size & Hint
Data range
For 40% of data, 2≤n≤40,1≤m≤40.
For 90% of data, 2≤n≤200,1≤m≤200.
For 100% of data, 2≤n≤1000,1≤m≤1000,1≤p≤m.
Category labels
Tags Click here to expandNOIP National League popular Group mainland region 2009 years
The idea was basically right, and the result blew 0.
forgot to consider the transfer of 1<-n.
#include <cstdio>#include<iostream>using namespacestd;#defineN 210intn,m,p;intA[n][n],cost[n];intTim[n],f[n][n];intans=-0x7fffffff;voiddp () { for(intI=1; i<=n;i++) f[1][i]=a[1][i]-cost[i],ans=max (ans,f[1][i]); for(intI=2; i<=m;i++){ for(intj=1; j<=n;j++){ for(intk=1; k<p;k++) {F[i][j]=max (f[i][j],tim[i-k-1]+a[i][j]-a[i-k-1][j-k-1]-cost[j-K]); Ans=Max (ans,f[i][j]); }}} printf ("%d\n", ans);}intMain () {scanf ("%d%d%d",&n,&m,&p); for(intI=1; i<=n;i++){ for(intj=1; j<=m;j++) {scanf ("%d",&A[j][i]); } } for(intI=1; i<=n;i++) scanf ("%d", cost+i); for(intI=2; i<=m;i++){ for(intj=1; j<=n;j++) {A[i][j]+=a[i-1][j-1]; Tim[i]=Max (tim[i],a[i][j]); }} dp (); return 0;}
The following:
F (i,j) represents the maximum number of coins to be obtained at the first J position of the I time, there are n^2 states (because the upper bounds of N and M are equal, so n is substituted in the back), and the P is enumerated for each state, so that the complexity is O (n^3), which can be 90 points
F (i,j) =max{fm[i-k-1]+val[i-k][j-k][k]-cost[j-k] | 0<k<p}
Fm[i] Indicates the maximum number of gold coins to go to the first second, i.e. Fm[i]=max (fm[i-1], max{f (i,j) | 0<j<n}) (as this step may not be selected), and then the F can be obtained
Cost[i] represents the cost of producing robots in the first position
VAL[I][J][K] is the number of gold coins that can be picked up in J position at the beginning of the first part of the second, the number of gold coins to be picked up from the No. 0 second to the first J position of the second a[i][j, and the number of gold coins that can be found in the J position of the first second of the a[i][j]=a[i-1][j-1]+. Then val[i-k][j-k][k]=a[i][j]-a[i-k-1][j-k-1], the equation becomes:
F (i,j) =max{fm[i-k-1]+a[i][j]-a[i-k-1][j-k-1]-cost[j-k] | 0<k<p}
This makes it easy to write a program, paying attention to the boundary conditions (the road is circular)
To get a full score, we need O (n^2) algorithm, on the original basis to reduce one dimension.
AC Code:
#include <cstdio>#include<iostream>#defineN 1010using namespacestd;intmon[n][n],w[n],f[n],n,m,p;intMain () {scanf ("%d%d%d",&n,&m,&p); for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) scanf ("%d",&Mon[i][j]); for(intI=1; i<=n;i++) scanf ("%d",&W[i]); for(intI=1; i<=m;i++){ for(intj=1; j<=n;j++) {//enumerate the current location, time intr=j-1, vi=0; if(!r) r=n;vi+=Mon[r][i]; for(intk=1; k<=p;k++) {//enumerate time to buy a robot if(i-k<0)Continue; F[i]=max (f[i],f[i-k]-w[r]+VI); if(r==1) R=n;Elser--; VI+=MON[R][I-K];//accumulate the money bought by this robot}}} printf ("%d", F[m]); return 0;}
1153 Road games