Ah... day by day...
Today, I saw a new program group established by the public, remembering that I was at a loss when I learned that it was a family planning task last summer ..
I remember reading the video and learning C. I found it too difficult. I learned Java again and found it easier to get started with Java than C...
Forget it now =-=
I just want to say to my schoolmates: Don't rush to ask which book is suitable for getting started it's a long road
-----------------------
I still like to complain. =-=,
I thought it was DFS long ago...
In fact, this question has something in common with dataworks ..
DP [I] [J] + = max (DP [I-1] [J], DP [I] [J-1], DP [I, j * k])... as for Boundary processing, this state equation is the core of this question.
At first, I wanted to remove array A and open two Arrays for ease of understanding. Then I used an array.
Every question can be optimized as much as possible if it is too big ..
1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 const int inf = -0x3f3f3f3f; 6 int maze[25][1010]; 7 int dp[25][1010]; 8 9 int main()10 {11 int t , n , m;12 while( cin >> t )13 {14 while( t-- )15 {16 cin >> n >> m;17 for( int i = 1 ; i<=n ; i++ )18 {19 for( int j = 1 ; j<=m ; j++ )20 {21 cin >> maze[i][j];22 }23 }24 for( int i = 0 ; i<=n ; i++ )25 dp[i][0] = inf;26 for( int j = 0 ; j<=m ; j++ )27 dp[0][j] = inf;28 dp[0][1] = dp[1][0] = 0;29 for( int i = 1 ; i<=n ; i++ )30 {31 for( int j = 1 ; j<=m ; j++ )32 {33 dp[i][j] = max( dp[i-1][j] , dp[i][j-1] );34 for( int k = 1 ; k<j ; k++ )35 {36 if( j%k==0 )37 dp[i][j] = max( dp[i][j] , dp[i][k] );38 }39 dp[i][j] += maze[i][j];40 }41 }42 cout << dp[n][m] << endl;43 }44 }45 return 0;46 }
View code
1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 const int inf = -0x3f3f3f3f; 6 int dp[25][1010]; 7 8 int main() 9 {10 int t , n , m , temp;11 while( cin >> t )12 {13 while( t-- )14 {15 cin >> n >> m;16 for( int i = 1 ; i<=n ; i++ )17 {18 for( int j = 1 ; j<=m ; j++ )19 {20 cin >> dp[i][j];21 }22 }23 for( int i = 1 ; i<=n ; i++ )24 {25 for( int j = 1 ; j<=m ; j++ )26 {27 temp = inf;28 if( i==1 && j==1 )29 continue;30 else if( i>=2 && j==1 )31 temp = max( temp , dp[i-1][j] );32 else if( i==1 && j>=2 )33 temp = max( temp , dp[i][j-1] );34 else35 temp = max( dp[i-1][j] , dp[i][j-1] );36 for( int k = 1 ; k<j ; k++ )37 {38 if( j%k==0 )39 temp = max( temp , dp[i][k] );40 }41 dp[i][j] += temp;42 }43 }44 cout << dp[n][m] << endl;45 }46 }47 return 0;48 }
View code
Today:
After a class reunion for a year, everyone had a tacit understanding of the hotel under the hotel =-=