Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector> // sorry kittens.. earl.hustej.net/files/Every_time_you_PJC.jpg
- #include <cstdio>
- using namespace std;
- int fastCountPrice(vector<unsigned int> p, int n)
- {
- unsigned int m[100][100];
- for (int i = 1; i < n; i++)
- m[i][i] = 0;
- for (int L=2; L < n; L++)
- {
- int j;
- for (int i=1; i<=n-L+1; i++)
- {
- j = i+L-1;
- m[i][j] = -1;
- unsigned int price;
- for (int k=i; k<=j-1; k++)
- {
- price = m[i][k] + m[k+1][j] + p[i-1]*p[j]+p[k];
- m[i][j] = m[i][j] < price ? m[i][j] : price;
- }
- }
- }
- return m[1][n-1];
- }
- int main ( int argc, char * argv[] )
- {
- cout << "Zadejte pocty sroubu pro jednotlive priruby:" << endl;
- vector<unsigned int> srouby;
- try
- {
- int input;
- char c;
- do
- {
- if ( scanf ( "%d%c", &input, &c ) != 2 || input < 1 )
- throw 2;
- srouby.push_back( input );
- } while ( c != '\n' );
- if ( srouby.size() < 2 )
- throw 1;
- }
- catch ( int e )
- {
- cout << "Nespravny vstup." << endl;
- return e;
- }
- cout << "Cena: " << fastCountPrice ( srouby, srouby.size() ) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment