Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int dp[105][105];
- int n;
- int matrica[105][105];
- int main()
- {
- cin>>n;
- for(int i=0; i<n; i++){
- for(int j=0; j<n-i; j++){
- cin>>matrica[i][j];
- }
- }
- for(int i=0; i<n; i++){
- for(int j=0; j<n-i; j++){
- dp[i][j]=2e9;
- }
- }
- dp[0][0]=matrica[0][0];
- for(int i=0; i<n; i++){
- for(int j=0; j<n-1; j++){
- if(i+1<n){
- dp[i+1][j]=min(dp[i+1][j], dp[i][j]+matrica[i+1][j]);
- }
- if(j+1<n){
- dp[i][j+1]=min(dp[i][j+1], dp[i][j]+matrica[i][j+1]);
- }
- if((j+1<n-i)and(i+1<n)){
- dp[i+1][j+1]=min(dp[i+1][j+1], dp[i][j]+matrica[i+1][j+1]);
- }
- }
- }
- int minimum=2e9;
- int i1=0;
- int j1=0;
- for(int i=0; i<n; i++){
- if(minimum>dp[i][n-1-i]){
- minimum=dp[i][n-1-i];
- i1=i+1;
- j1=n-i;
- }
- }
- cout<<minimum<<" "<<i1<<" "<<j1<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement