Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define i64 long long
- #define u32 unsigned int
- #define u64 unsigned long long
- #define Neg(v) memset((v), -1, sizeof(v))
- #define Zero(v) memset((v), 0, sizeof(v))
- #define ff first
- #define ss second
- #define sqr(x) ((x)*(x))
- #define INF LONG_LONG_MAX
- #define PI 2*acos(0)
- #define pb push_back
- #define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
- #define FLASH ios_base::sync_with_stdio(0);
- const double eps = 1e-9;
- //int r[]={1,0,-1,0};int c[]={0,1,0,-1}; ///4 Direction
- //int r[]={1,1,0,-1,-1,-1,0,1};int c[]={0,1,1,1,0,-1,-1,-1};///8 direction
- //int r[]={2,1,-1,-2,-2,-1,1,2};int c[]={1,2,2,1,-1,-2,-2,-1};///Knight Direction
- //int r[]={2,1,-1,-2,-1,1};int c[]={0,1,1,0,-1,-1}; ///Hexagonal Direction
- #define BIT(n) (1<<(n))
- #define AND(a,b) ((a) & (b))
- #define OR(a,b) ((a) | (b))
- #define XOR(a,b) ((a) ^ (b))
- #define Check(n, pos) (n & (1<<pos))
- #define Set(n, pos) (n | (1<<pos))
- int Unset(int a, int i)
- {
- int mask;
- mask = 1 << i;
- a = a & ~mask;
- return a;
- }
- template< class T > inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); }
- template< class T > inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); }
- template <typename T> string NumberToString ( T Number ) { ostringstream ss; ss << Number; return ss.str(); }
- int power( int x, int n)
- {
- if(n==0)return 1;
- else if(n%2==0)
- {
- int y=power(x,n/2);
- return y*y;
- }
- else
- return x*power(x,n-1);
- }
- /// Tokens
- /*
- vector <int> lon;
- vector <string> los;
- void token_of_string()
- {
- char line[1000];
- gets(line);
- stringstream ss( line );
- string temp;
- while( ss >> temp )
- los.pb( temp );
- }
- void token_of_number()
- {
- char line[1000];
- gets(line);
- stringstream ss( line );
- int num;
- while( ss >> num )
- lon.pb( num );
- }
- */
- ///1st,2nd,3rd
- /*
- void func( int num )
- {
- printf("%d",num);
- if(num % 10 == 1 && (num/10)%10!=1) printf("st");
- else if(num %10==2 && (num/10)%10!=1) printf("nd");
- else if(num %10==3 && (num/10)%10!=1) printf("rd");
- else printf("th");
- }
- */
- /***
- int nth_element( int a , int d , int n)
- {
- return a + (n-1) * d;
- }
- int nth_summation( int a , int d , int n)
- {
- int temp;
- temp = 2 * a + (n-1)*d;
- temp *= n;
- temp /= 2;
- return temp;
- }
- ***/
- /***
- n row ; m collumn
- 2d in 1d
- int x = A / m , y = A % m;
- visited[0][x] = 1, visited[1][y] = 1,visited[2][x+y] = 1,visited[3][n-x+y] = 1;
- ***/
- #ifdef blackfyre
- #define debug(args...) {cerr<<"Debug: "; dbg,args; cerr<<endl;}
- #else
- #define debug(args...) // Just strip off all debug tokens
- #endif
- struct debugger{
- template<typename T> debugger& operator , (const T& v){
- cerr<<v<<" ";
- return *this;
- }
- }dbg;
- struct data
- {
- string x ;
- double a , b ;
- };
- data v1[510];
- int n ;
- int visited[510][2][5] ;
- double dp[510][2][5] ;
- double call( int pos , bool st , int c1 )
- {
- if( pos >= n )
- {
- if( st && c1 == 4 )
- return 0.0;
- else
- return 9999 ;
- }
- if( visited[pos][st][c1] != -1 )
- return dp[pos][st][c1] ;
- visited[pos][st][c1] = 1 ;
- double option1 = 99999.0, option2 = 99999.0, option3 = 99999.0;
- if(!st)
- option1 = v1[pos].a + call(pos+1,1,c1+1);
- option2 = v1[pos].b + call(pos+1,st,c1+1);
- option3 = call(pos+1,st,c1);
- return dp[pos][st][c1] = min( option1 , min(option2 , option3 ) ) ;
- }
- int main()
- {
- #ifdef blackfyre
- //freopen("F:/in.txt","r",stdin);
- //freopen("F:/out.txt","w",stdout);
- #endif // blackfyre
- while( cin >> n )
- {
- Neg(visited);
- cin.ignore();
- for( int A = 0 ; A < n ; A++ )
- {
- cin >> v1[A].x ;
- cin >> v1[A].a ;
- cin >> v1[A].b ;
- }
- double ans = call(0,0,0) ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement