Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("taxe.in");
- ofstream fout("taxe.out");
- const int CMAX = 205;
- int desert[CMAX][CMAX] , desert2[CMAX][CMAX] , n , m , i , j , minim = 90000;
- void citire()
- {
- fin >> n >> m;
- for(i=1;i<=n;i++)
- for(j=1;j<=m;j++){
- fin >> desert[i][j];
- desert2[i][j] = desert[i][j];
- }
- }
- void afisare()
- {
- for(i=1;i<=n;i++)
- {
- for(j=1;j<=m;j++)
- {
- cout << desert2[i][j] << " ";
- }
- cout << '\n';
- }
- cout << '\n';
- }
- bool OK(int coi,int coj)
- {
- if(coi<=0||coj<=0||coi>n||coj>m)
- return false;
- return true;
- }
- int main()
- {
- citire();
- for(j=m-1;j>=1;j--)
- {
- for(i=1;i<=n;i++)
- {
- if(i==1)
- {
- if(desert2[i][j+1]>desert2[i+1][j+1]) desert2[i][j]+= desert2[i+1][j+1];
- else desert2[i][j]+= desert2[i][j+1];
- }
- else if(i==n)
- {
- if(desert2[i][j+1]>desert2[i-1][j+1]) desert2[i][j]+= desert2[i-1][j+1];
- else desert2[i][j]+= desert2[i][j+1];
- }
- else{
- if(desert2[i-1][j+1]>desert2[i+1][j+1])
- {
- if(desert2[i+1][j+1]<desert2[i][j+1])
- {
- desert2[i][j]+= desert2[i+1][j+1];
- }
- else
- {
- desert2[i][j]+= desert2[i][j+1];
- }
- }
- else
- {
- if(desert2[i-1][j+1]>desert2[i][j+1])
- {
- desert2[i][j]+= desert2[i][j+1];
- }
- else
- {
- desert2[i][j]+= desert2[i-1][j+1];
- }
- }
- }
- }
- }
- for(i=1;i<=n;i++)
- if(minim>desert2[i][1]) minim = desert2[i][1];
- fout << minim;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement