Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Folosirea unui vector de 1000 de elemente de tip long long pe care aplicam un procedeu de programare dinamica,
- astfel:
- V – vectorul, X – elementul citit, j – pozitia curenta din vector (coloana a matricei),
- i – capatul drept al vectorului(linie a matricei).
- daca pozitia curenta este 1, atunci V[j] = V[j] + x;
- daca pozitia curenta este i, atunci V[j] = V[j - 1] + x;
- altfel V[j] = min(V[j], V[j - 1]) + x.
- */
- #include <fstream>
- #include <iostream>
- using namespace std;
- ifstream f("vizita.in");
- ofstream g("vizita.out");
- int n;
- long long x,v[2000];
- int main()
- {
- f>>n;
- int i,j;
- for(i=1;i<=n;++i)
- {
- for(j=1;j<=i;++j)
- {
- f>>x;
- if(j==1)
- v[j]=v[j]+x;
- else
- {
- if(j==i)
- v[j]=v[j-1]+x;
- else
- v[j]=min(v[j],v[j-1])+x;
- }
- }
- }
- int n2=n*2-1;
- for(int ii=i;ii<=n2;++ii)
- {
- for(int jj=j-1;jj<=ii;++jj)
- {
- f>>x;
- if(jj==j-1)
- v[jj]=v[jj]+x;
- else
- {
- if(jj==ii)
- v[jj]=v[jj-1]+x;
- else
- v[jj]=min(v[jj],v[jj-1])+x;
- }
- }
- }
- g<<v[n2];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement