Advertisement
MaskerQwQ

P1490 机器人捡垃圾

Jun 2nd, 2022
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int N=205;
  4. int rubbish[N][N],dp[N][N];
  5. void init(int n,int m)
  6. {
  7.     for(int i=0;i<=n;i++){
  8.         dp[0][i]=0;
  9.     }
  10.     for(int i=0;i<=m;i++){
  11.         dp[i][0]=0;
  12.     }
  13. }
  14. int main(){
  15.     int n,m;
  16.     while(scanf("%d%d",&n,&m)!=EOF){
  17.         init(n,m);
  18.         memset(dp,0,sizeof(dp));
  19.         for(int i=1;i<=n;i++){
  20.             for(int j=1;i<=m;j++){
  21.                 cin>>rubbish[i][j];
  22.             }
  23.         }  
  24.         for(int i=1;i<=n;i++){
  25.             for(int j=1;j<=m;j++){
  26.                 dp[i][j]=max(dp[i-1][j],dp[i][j-1])+rubbish[i][j];
  27.             }
  28.         }
  29.         cout<<dp[n][m]<<endl;
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement