Original title:
After a successful small W to get iPhone, downloaded a tower defense game. The objective is to stop the zombie through the map.
Maps can be seen as a line segment of length n, and this segment is divided into n pieces of small unit length segments. Zombie takes t seconds to pass a small segment. In each small segment in W can be placed a small column. The tower has three kinds:
red tower, x per second are causing damage by enemy tower.
Green tower, y per second has caused damage by enemy tower.
Blue tower, the tower has been through the enemy's decelerating, need to spend more seconds to z by 1 unit length.
"By being" is defined as a zombie in a small unit length segments tower is located, "has passed" is defined as a zombie has left this small segment.
Green tower, tower blue effect can be superimposed. In other words, if a zombie has passed a green column, b blue column, it will be ay damage second column from the green, and takes seconds to t + bz by a unit length.
Small W would like to know how much damage he can cause up to zombies.
1<=n<=100,0<=x,y,z<=60000,1<=t<=3
n is small, the number of ice towers and poison towers and can not exceed n
Therefore, a f [i] [j] [k] n ^ 3 DP, denotes the i-th line go zombie, stepped on the j-th column toxic, k can eat ice tower maximum damage
But I did 1A, where the problem lie
At first I was written this way
1 for(int i=1;i<=n;++i) 2 for(int j=0;j<=i;++j) 3 for(int k=0;j+k<=i;++k){ 4 f[i][j][k]=max(f[i][j][k],f[i-1][j][k]+(x+j*y)*(t+k*z)); 5 if(j) f[i][j][k]=max(f[i][j][k],f[i-1][j-1][k]+(j-1)*y*(t+k*z)); 6 if(k) f[i][j][k]=max(f[i][j][k],f[i-1][j][k-1]+j*y*(t+(k-1)*z)); 7 }
The initial value is 0 then f
A few sample results, because this way it is possible from the f [0] [1] [0] is transferred to f [1] [1] [0]
I then hastily put j <= i, and j + k <= i into j <i and j + k <i
Obviously this is wrong drops, attention j and k is expressed through the i-th line, I stepped on a poisonous j k tower ice tower, before the statement is unclear
WA loved the place
F should be the correct method to change the initial value of the full set -INF, f [0] [0] [0] is set to 0
Suddenly I thought this was quite common practice for preventing illegal state into chaos
Probably a year back pit forget ha ha
Code:
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 using namespace std; 7 long long n,x,y,z,t; 8 long long f[110][110][110]; 9 void rvs(){ 10 for(int i=0;i<=n;++i) 11 for(int j=0;j<=n;++j) 12 for(int k=0;k<=n;++k) 13 f[i][j][k]=-9999999999999999LL; 14 f[0][0][0]=0; 15 return ; 16 } 17 int main(){ 18 //freopen("ddd.in","r",stdin); 19 while(scanf("%lld%lld%lld%lld%lld",&n,&x,&y,&z,&t)!=EOF){ 20 rvs(); 21 for(int i=1;i<=n;++i) 22 for(int j=0;j<=i;++j) 23 for(int k=0;j+k<=i;++k){ 24 f[i][j][k]=max(f[i][j][k],f[i-1][j][k]+(x+j*y)*(t+k*z)); 25 if(j) f[i][j][k]=max(f[i][j][k],f[i-1][j-1][k]+(j-1)*y*(t+k*z)); 26 if(k) f[i][j][k]=max(f[i][j][k],f[i-1][j][k-1]+j*y*(t+(k-1)*z)); 27 } 28 long long ans=0; 29 for(int i=0;i<=n;++i) 30 for(int j=0;j<=n;++j) 31 ans=max(ans,f[n][i][j]); 32 printf("%lld\n",ans); 33 } 34 return 0; 35 }