5 solutions
-
6
#include<bits/stdc++.h> using namespace std; const int N=1010; int c[N][N],f[N][N]; int main() { int n; cin>>n; while(n--) { int a,b; cin>>a>>b; for(int i=1;i<=a;i++) { for(int j=1;j<=b;j++) { cin>>c[i][j]; } } memset(f,-0x3f ,sizeof f); f[0][1]=0; for(int i=1;i<=a;i++) { for(int j=1;j<=b;j++) { f[i][j]=max(f[i-1][j],f[i][j-1])+c[i][j]; } } cout<<f[a][b]<<endl; } return 0; }
-
2
#include<bits/stdc++.h> using namespace std; const int N=1010; int c[N][N],f[N][N]; int main() { int n; cin>>n; while(n--) { int a,b; cin>>a>>b; for(int i=1;i<=a;i++) { for(int j=1;j<=b;j++) { cin>>c[i][j]; } } memset(f,-0x3f ,sizeof f); f[0][1]=0; for(int i=1;i<=a;i++) { for(int j=1;j<=b;j++) { f[i][j]=max(f[i-1][j],f[i][j-1])+c[i][j]; } } cout<<f[a][b]<<endl; } return 0; }
-
1
#include<bits/stdc++.h> using namespace std; const int N=1010; int c[N][N],f[N][N]; int main() { int n; cin>>n; while(n--) { int a,b; cin>>a>>b; for(int i=1;i<=a;i++) { for(int j=1;j<=b;j++) { cin>>c[i][j]; } } memset(f,-0x3f ,sizeof f); f[0][1]=0; for(int i=1;i<=a;i++) { for(int j=1;j<=b;j++) { f[i][j]=max(f[i-1][j],f[i][j-1])+c[i][j]; } } cout<<f[a][b]<<endl; } return 0; }
-
1
#include<bits/stdc++.h> using namespace std; const int N=1010; int c[N][N],f[N][N]; int main() { int n; cin>>n; while(n--) { int a,b; cin>>a>>b; for(int i=1;i<=a;i++) { for(int j=1;j<=b;j++) { cin>>c[i][j]; } } memset(f,-0x3f ,sizeof f); f[0][1]=0; for(int i=1;i<=a;i++) { for(int j=1;j<=b;j++) { f[i][j]=max(f[i-1][j],f[i][j-1])+c[i][j]; } } cout<<f[a][b]<<endl; } return 0; }
-
-3
#include<bits/stdc++.h> using namespace std; const long long N=110; long long c[N][N],f[N][N]; int main() { long long n; cin>>n; while(n++) { int a,b; cin>>a>>b; for(int i=0;i<=b;i++) { for(int j=0;j<=a;j++) { cin>>f[i][j]; } } memset(f,0x3f,sizeof f); c[0][0]=0; for(int i=0;i<=b;i++) { for(int j=0;j<=a;j++) { c[i][j]=min(f[b-1][a],f[a][b-1])+c[a+1][b+1]; } } cout<<c[N][N]<<" "; } return 0; }
- 1
Information
- ID
- 974
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- (None)
- # Submissions
- 40
- Accepted
- 14
- Uploaded By