2 条题解

  • 1
    @ 2023-7-23 19:56:36
    #include<iostream>
    #include<string>
    #include<cctype>
    #include<cmath>
    #include<cstdlib>
    #include<cstring>
    #include<vector>
    #include<algorithm>
    #include<map>
    #include<set>
    #include<iomanip>
    using namespace std;
    #define LL long long
    const int N = 1e6+10;
    const int INF = 0x3f3f3f3f;
    int n,a[105][105]; 
    int main(){
    	//freopen("","r",stdin);
    	//freopen("","w",stdout);
    	cin>>n;
    	for(int i=1;i<=n;i++)
    		for(int j=1;j<=n;j++)
    			cin>>a[i][j];
    	for(int i=1;i<=n;i++){
    		for(int j=1;j<=n;j++){
    			if(i!=1&&j!=1)a[i][j]+=min(a[i-1][j],a[i][j-1]);
    			else if(i==1&&j==1)a[i][j]=a[i][j];
    			else if(i==1)a[i][j]=a[i][j-1]+a[i][j];
    			else if(j==1)a[i][j]=a[i-1][j]+a[i][j];
    		}
    	}
    	cout<<a[n][n];
    	return 0;
    }
    
    
    • 0
      @ 2021-10-25 22:38:03
      #include<iostream>
      #include<cstdio>
      #include<cmath>
      #include<algorithm>
      using namespace std;
      int a[110][110],f[110][110];
      int main(){
          int n;
          cin>>n;
          for(int i=1;i<=n;i++){
              for(int j=1;j<=n;j++){
                  cin>>a[i][j];
                  if(i==1) f[i][j] = f[i][j-1]+a[i][j];
                  else if(j==1) f[i][j] = f[i-1][j]+a[i][j];
                  else f[i][j] = a[i][j];
                 }
              }
          for(int i=1;i<=n;i++){
              for(int j=1;j<=n;j++){
                  f[i][j] += min(f[i-1][j],f[i][j-1]);
              }
          }
          cout<<f[n][n];
          return 0;
      } 
      
      
      
      • 1

      信息

      ID
      1412
      时间
      1000ms
      内存
      128MiB
      难度
      4
      标签
      递交数
      61
      已通过
      28
      上传者