6 条题解

  • 2
    @ 2022-3-5 19:07:53
    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <queue>
    #include <math.h>
    #include <vector>
    #include <algorithm>
    #include <iomanip>
    #include <stack>
    
    using namespace std;
    
    #define LL long long
    const int N =1e5+10;
    const int INF =0x3f3f3f3f;
    LL a[10010][10010];
    LL t,n,m,ans;
    int main(){
    	cin>>t;
    	while(t--){
    		cin>>n>>m;
    		for(LL i=1;i<=n;i++){
    			for(LL j=1;j<=m;j++){
    				cin>>a[i][j];
    				a[i][j]+=max(a[i-1][j],a[i][j-1]);
    			}
    		}
    		cout<<a[n][m]<<endl;
    	}
    	return 0;
    }
    • 2
      @ 2021-10-10 10:34:33
      #include <iostream>
      #include <algorithm>
      using namespace std;
      const int N = 1e3 + 10; 
      int a[N][N];
      int main(){
      	int n;
      	cin >> n;
      	for(int i = 1; i <= n; i++){
      		for(int j = 1; j <= i; j++){
      			cin >> a[i][j];
      		}
      	}
      	for(int i = 1; i <= n; i++){
      		for(int j = 1; j <= i; j++){
      			a[i][j] = max(a[i-1][j-1], a[i-1][j]) + a[i][j];
      		}
      	}
      	int maxx = 0;
      	for(int i = 1; i <= n; i++){
      		maxx = max(maxx, a[n][i]);
      	}
      	cout << maxx << endl;
      }
      
      • 1
        @ 2023-4-30 16:12:11
        #include<cstdio>
        #include<algorithm>
        #include<iostream>
        using namespace std;
        int f[1001][1001],r,c,i,j;
        int t;
        int main()
        {
        	scanf("%d",&t);
        	while(t--)
        	{
        		scanf("%d%d",&r,&c);
        		for(i=1;i<=r;++i)
        		{
        			for(j=1;j<=c;++j)
        			{
        				scanf("%d",&f[i][j]);
        			}
        		}
        		for(i=1;i<=r;++i)
        		{
        			for(j=1;j<=c;++j)
        			{
        				f[i][j]+=max(f[i-1][j],f[i][j-1]);
        			}
        		}
        		printf("%d\n",f[r][c]);
        	}
        	return 0;
        }
        
        • 0
          @ 2023-12-3 18:55:56
          /************************************
          Note Book:
          ************************************/
          #include <iostream>
          #include <cstdio>
          #include <iomanip>
          #include <cmath>
          #include <algorithm>
          #include <cstring>
          #include <string>
          #include <stack>
          #include <queue>
          #include <math.h>
          #define LL long long
          using namespace std;
          const int INF = 0x3f3f3f3f;
          const int N = 1e5 + 10;
          int a[105][105];
          int main()
          {
          	int t;
          	cin >> t;
          	while( t-- )
          	{
          		int n , m ;
          		cin >> n >> m;
          		for(int i = 1; i <= n; i++)
          		{
          			for(int j = 1; j <= m; j++)
          			{
          				cin >> a[i][j];
          			}
          		}
          		for(int i = 1; i <= n; i++)
          		{
          			for(int j = 1; j <= m; j++)
          			{
          				a[i][j] += max(a[i-1][j] , a[i][j-1]);
          			}
          		}
          		cout << a[n][m] << endl;
          	}
          	return 0;
          }
          
          • 0
            @ 2021-10-10 10:35:29
            #include <iostream>
            #include <stdio.h>
            #include <string.h>
            #include <math.h>
            #include <queue>
            #include <stack>
            #include <algorithm>
            const int N = 1e6 + 10;
            using namespace std;
            int t, n, m, dp[110][110], ans;
            int read() {
                char ch = getchar();
                int f = 1, num = 0;
            
                while (ch < '0' || ch > '9') {
                    if (ch == '-')
                        f = -1;
            
                    ch = getchar();
                }
            
                while (ch >= '0' && ch <= '9') {
                    num = num * 10 + ch - '0';
                    ch = getchar();
                }
            
                return num * f;
            }
            int main() {
                t = read();
            
                while (t--) {
                    n = read(), m = read();
            
                    for (int i = 1; i <= n; i++)
                        for (int j = 1; j <= m; j++)
                            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + read();
            
                    printf("%d\n", dp[n][m]);
                }
            }
            
            • -1
              @ 2021-10-10 10:30:23
              #include <math.h>
              #include <stdio.h>
              #include <iostream>
              #include <string.h>
              #include <algorithm>
              using namespace std;
              int a[105][105];
              int main()
              {
                  int t;
                  cin >> t;
                  while(t--)
                  {
                      int n , m;
                      cin >>n >> m;
                      for(int i = 1 ; i <= n ; i++)
                          for(int j =1 ; j <= m ; j++)
                              cin >> a[i][j];
                      for(int i = 1 ; i <= n ; i++)
                          for(int j = 1 ;j <= m ; j++)
                              a[i][j] += max(a[i-1][j] , a[i][j-1]);
              
                      cout << a[n][m] << endl;
                  }
                  return 0;
              }
              
              • 1

              信息

              ID
              1341
              时间
              1000ms
              内存
              256MiB
              难度
              4
              标签
              递交数
              260
              已通过
              110
              上传者