void Tim::ProcessCoherentInterval( int aNave, int aPts, double *aXvec, double *aYvec ) { short *dst; int cnt,lim; int isComplex; // Get format isComplex = Dp()->Adc()->IsComplexFmt(); if( mLog&TIM_LOG_PCOHI ){ printf("Tim:nav=%d,pts=%d,cmplx=%d\n", aNave,aPts,isComplex); } // Sanity check args to prevent downstream ambiguous errors if( aPts >= mMaxSamp ){ fprintf(stderr,"Tim::pts > max samples\n"); return; } if( aPts <=0 ){ fprintf(stderr,"Tim::pts <= 0\n"); return; } if( aNave <=0 ){ fprintf(stderr,"Tim::ave <= 0\n"); return; } // Capture the coherent number of required samples // The adc interface is really 2k sample words so // in complex cases we are really only getting 1k complex // samples each time. dst = mInput; cnt = 0; lim = aPts; Dp()->Adc()->FlushSamples(); while( cnt<lim ) { Dp()->Adc()->Get2kSamples( dst ); dst += 2048; cnt += 2048; } if( mLog&TIM_LOG_PCOHI ){ printf("Tim::ProcessCoherentInterval: %d words, %d samples, %d coll\n", lim, aPts,cnt); } // Format and output the X values PerformOutputX( isComplex, aPts, aXvec ); // Format and output the Y values PerformOutputY( isComplex, aPts, aYvec ); }
edge *Join(edge *a, point *u, edge *b, point *v, int side) { edge *e = Make_edge(u, v); if (side == 1) { if (Oi(a) == u) Splice(Op(a), e, u); else Splice(Dp(a), e, u); Splice(b, e, v); } else { Splice(a, e, u); if (Oi(b) == v) Splice(Op(b), e, v); else Splice(Dp(b), e, v); } return e; }
long long Dp( int beg, int end ) { long long tmp; long long& val=opt[beg][end]; if ( val == INF ){ for ( int i=beg; i<end; ++i ){ tmp = Dp( beg, i ) + Dp( i+1, end ) + mat[beg].row*mat[i].col*mat[end].col; if ( tmp < val ){ val = tmp; pivot[beg][end] = i; } } } return val; }
int main(){ for(ll i = 0; i < 901; ++i) for(ll j = 0; j < 8101; ++j) dp[i][j] = -1, pr[i][j] = (int)1e9; for(ll i = 1; i <= 9; ++i) dp[i][i * i] = 1, pr[i][i * i] = i; scanf("%d", &q); for(ll i = 1; i <= q; ++i){ ll x, y; scanf("%d %d", &x, &y); if(x > 900 || y > 8100){ printf("No solution\n"); continue; } ll len = Dp(x, y); if(len > 100){ printf("No solution\n"); continue; } while(len){ ll now = pr[x][y]; printf("%d", now); x = x - now; y = y - now * now; --len; } printf("\n"); } return 0; }
int main() { while (~scanf("%d %d", &n, &m)) { init(n); for (int i = 1; i <= n; ++i) { scanf("%I64d", s + i); s[i] += s[i - 1]; } dp[1] = s[1] * s[1] + m; q.push_back(0); for (int i = 1; i <= n; ++i) { while (q.size() >= 2 && Up(q[1], q.front()) <= s[i] * Down(q[1], q.front())) { // printf(" %d\n", q[1]); // printf("--- %I64d %d\n", dp[i], q.size()); q.pop_front(); } if (!q.empty()) Dp(i, q.front()); // printf("%I64d %d\n", dp[i], q.size()); while (q.size() >= 2 /*&& 1, printf("--- %I64d %d\n *** %I64d %I64d\n", dp[i], q.back(), Up(i, q.back()) * Down(q.back(), q[q.size() - 2]), Up(q.back(), q[q.size() - 2]) * Down(i, q.back())) */&& Up(i, q.back()) * Down(q.back(), q[q.size() - 2]) <= Up(q.back(), q[q.size() - 2]) * Down(i, q.back())) { // ; // printf(" %d\n", q[1]); q.pop_back(); } q.push_back(i); // printf(" %d\n", q.size()); } printf("%I64d\n", dp[n]); } }
void Solve( ) { for ( int i=0; i<nmat; ++i ) for ( int j=0; j<nmat; ++j ) opt[i][j] = (i==j ? 0 : INF); Dp( 0, nmat-1 ); printf( "Case %d: ", ++ncase ); Print( 0, nmat-1 ); printf( "\n" ); }
void Work(ll l, ll r) { pair Ans; while (l <= r) { ll pow = 1, L = 0, n_pow; while (l + (n_pow = pow * 10) <= r + 1 && (l % n_pow == 0)) pow = n_pow, L++; pair Temp = Dp(L, Digit(l / pow), Ans.rest); Ans.Renew(Temp); l += pow; } printf(LL "\n", Ans.cnt); }
/******************************************************************* * * NAME : accept_new_position() * * * DESCRIPTION : Updates old matrices with the new WF and inverse. * */ void Slater::accept_new_position() { if (active_particle < N) { for (int i = 0; i < N; i++) Dp(i, active_particle) = Dp_new(i, active_particle); Dp_inv = Dp_inv_new; } else { for (int i = 0; i < N; i++) Dm(i, active_particle - N) = Dm_new(i, active_particle - N); Dm_inv = Dm_inv_new; } }
Expression* sintactico::Dp() { if(CurrentToken->tipo == MENOR) { CurrentToken = Lexer->NexToken(); Expression* izq = E(); Expression* der = Dp(); if(der != NULL) return new exprLessThan(izq,der,Lexer->linea); return izq; } else if(CurrentToken->tipo == MENOR_IGUAL) { CurrentToken = Lexer->NexToken(); Expression* izq = E(); Expression* der = Dp(); if(der != NULL) return new exprLessAndEqual(izq,der,Lexer->linea); return izq; } else if(CurrentToken->tipo == MAYOR) { CurrentToken = Lexer->NexToken(); Expression* izq = E(); Expression* der = Dp(); if(der != NULL) return new exprGreaterThan(izq,der,Lexer->linea); return izq; } else if(CurrentToken->tipo == MAYOR_IGUAL) { CurrentToken = Lexer->NexToken(); Expression* izq = E(); Expression* der = Dp(); if(der != NULL) return new exprGreaterAndEqual(izq,der,Lexer->linea); return izq; } return NULL; }
pair Dp(int L, int Sum, int rest) { if (Sum > K) Sum = K; pair& Now = f[L][Sum][rest]; if (Now.vis) return Now; Now.vis = true; if (!L) { int val = Sum + rest; Now = pair(val); return Now; } Now = pair(rest); for (int i = 0; i < 10; i++) Now.Renew(Dp(L - 1, Sum + i, Now.rest)); return Now; }
inline ll Dp(ll s, ll p){ if(~dp[s][p]) return dp[s][p]; dp[s][p] = (int)1e9; for(ll k = 1; k <= 9; ++k){ if(s - k >= 0 && p - (k * k) >= 0){ ll val = Dp(s - k, p - (k * k)) + 1; if(val == dp[s][p]){ if(k <= pr[s][p]) pr[s][p] = k; } if(val < dp[s][p]){ dp[s][p] = val; pr[s][p] = k; } } } return dp[s][p]; }
/******************************************************************* * * NAME : init(); * * * DESCRIPTION : Initializes the Slater matrix with position * values. * */ void Slater::init() { // Updating the whole matrix. for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { Dp(j, i) = orbital->evaluate(r_new.row(i), nx(j), ny(j)); Dm(j, i) = orbital->evaluate(r_new.row(i + N), nx(j), ny(j)); } } Dp_new = Dp; Dm_new = Dm; // Calulating the inverse using Armadillo. Dp_inv = inv(Dp).t(); Dm_inv = inv(Dm).t(); Dp_inv_new = Dp_inv; Dm_inv_new = Dm_inv; }
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { int rowlen = obstacleGrid.size(); int colen = obstacleGrid[0].size(); vector<vector<int>> Dp(rowlen,vector<int>(colen,0)); for(int i=0; i<rowlen; ++i){ if(obstacleGrid[i][0] == 1) break; Dp[i][0] = 1; } for(int i=0; i<colen; ++i){ if(obstacleGrid[0][i] == 1) break; Dp[0][i] = 1; } for(int i=1; i<rowlen; ++i){ for(int j=1; j<colen; ++j){ if(obstacleGrid[i][j] == 1) Dp[i][j] = 0; else Dp[i][j] = Dp[i-1][j]+Dp[i][j-1]; } } return Dp[rowlen-1][colen-1]; }
int minCut(string s) { int n = s.size(); vector<int> Dp( n+1, 0 ); vector<unsigned long long> F(n+1,0), R(n+1,0), P(n+1,0); P[0] = 1; for( int i = 0; i < n; i++ ) { P[i+1] = P[i] * 31ll; if(i) F[i] = F[i-1]; F[i] += P[i] * s[i]; } for( int i = n-1; i >= 0; i-- ) { if( i < n-1 ) R[i] = R[i+1]; R[i] += P[ n - i - 1 ] * s[i]; } for( int i = n-1; i >= 0; i-- ) { Dp[i] = Dp[i+1] + 1; for( int j = i; j <n ; j++ ) { unsigned long long ff = F[j]; if(i) ff -= F[i-1]; unsigned long long rr = R[i]; if(j+1<n) rr -= R[j+1]; if( n - j - 1 > i ) ff *= P[ n - j - 1 - i ]; else rr *= P[ i - n + j + 1 ]; if( ff == rr ) { Dp[i] = min( Dp[i] , Dp[j+1] + 1 ); } } } return Dp[0] - 1; }
int main(int argc, char *argv[]) { #include "setRootCase.H" #include "createTime.H" #include "createMesh.H" #include "readThermodynamicProperties.H" #include "readTransportProperties.H" #include "createFields.H" #include "initContinuityErrs.H" pimpleControl pimple(mesh); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Info<< "\nStarting time loop\n" << endl; while (runTime.loop()) { Info<< "Time = " << runTime.timeName() << nl << endl; #include "readTimeControls.H" #include "compressibleCourantNo.H" #include "rhoEqn.H" // --- Pressure-velocity PIMPLE corrector loop while (pimple.loop()) { fvVectorMatrix UEqn ( fvm::ddt(rho, U) + fvm::div(phi, U) - fvm::laplacian(mu, U) ); solve(UEqn == -fvc::grad(p)); // --- Pressure corrector loop while (pimple.correct()) { volScalarField rAU(1.0/UEqn.A()); U = rAU*UEqn.H(); surfaceScalarField phid ( "phid", psi *( (fvc::interpolate(U) & mesh.Sf()) + fvc::ddtPhiCorr(rAU, rho, U, phi) ) ); phi = (rhoO/psi)*phid; volScalarField Dp("Dp", rho*rAU); fvScalarMatrix pEqn ( fvm::ddt(psi, p) + fvc::div(phi) + fvm::div(phid, p) - fvm::laplacian(Dp, p) ); pEqn.solve(); phi += pEqn.flux(); #include "compressibleContinuityErrs.H" U -= rAU*fvc::grad(p); U.correctBoundaryConditions(); } } rho = rhoO + psi*p; runTime.write(); Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << endl; } Info<< "End\n" << endl; return 0; }
void SgCtlIf::Configure() { long long ifHz = 1575000000; long long lo0,lo1; long long dHz; Dp()->Lo(0)->SetLog(0); Dp()->Lo(1)->SetLog(0); switch( gSgCfgMode ){ case 0: printf("SgConfigure: B=%ld\n",gSgCfgHz); Dp()->Lo(0)->SetMainPower( 0 ); Dp()->Lo(0)->SetAuxPower( 0 ); Dp()->Lo(0)->SetAuxEnable( 1 ); Dp()->Lo(0)->SetFrequency( gSgCfgHz ); break; case 1: printf("SgConfigure: C=%ld\n",gSgCfgHz); Dp()->Lo(1)->SetMainPower( 0 ); Dp()->Lo(1)->SetAuxPower( 0 ); Dp()->Lo(1)->SetAuxEnable( 1 ); Dp()->Lo(1)->SetFrequency( gSgCfgHz ); break; case 2: default: // approx as 1 dB/MHz dHz = gSgCfgAttenDb; lo0 = ifHz + dHz; lo1 = ifHz + dHz + gSgCfgHz; printf("SgConfigure: %lld %lld %lld\n",lo0,lo1,dHz); Dp()->Lo(0)->SetAuxEnable( 0 ); Dp()->Lo(1)->SetAuxEnable( 0 ); Dp()->Lo(0)->SetMainPower( 0 ); Dp()->Lo(1)->SetMainPower( 0 ); Dp()->Lo(0)->SetFrequency( lo0 ); Dp()->Lo(1)->SetFrequency( lo1 ); break; } }
void Splice(edge *a, edge *b, point *v) { edge *next; if (Oi(a) == v) next = On(a), On(a) = b; else next = Dn(a), Dn(a) = b; if (Oi(next) == v) Op(next) = b; else Dp(next) = b; if (Oi(b) == v) On(b) = next, Op(b) = a; else Dn(b) = next, Dp(b) = a; }
//------------------------------------------------------------------------------ void SgCtlIf::SvcCmd( TcpSvrCon *tsc, Cli *cli ) { char *cmdStr; const char *rspStr; char *arg1,*arg2; char lineBf[128]; int dn; cmdStr = CliArgByIndex( cli, 0 ); printf("Cmd= %s\n",cmdStr); //////////////////////////////////////// if( 0==strcmp(cmdStr,"help") ){ rspStr=helpStr; TcpSvrWrite(tsc,rspStr,strlen(rspStr)); return; } //////////////////////////////////////// if( 0==strcmp(cmdStr,"sg-lock-status") ){ arg1 = CliArgByIndex( cli, 1 ); if( !arg1 ) { SvcErr(tsc); return; } dn = atoi(arg1); if( dn<0 || dn>1 ) dn=0; sprintf( lineBf,"%d\n", Dp()->Lo(dn)->GetLock() ); TcpSvrWrite(tsc,lineBf,strlen(lineBf)); return; } //////////////////////////////////////// if( 0==strcmp(cmdStr,"sg-hz") ){ arg1 = CliArgByIndex( cli, 1 ); if( !arg1 ) { SvcErr(tsc); return; } gSgCfgHz = atol( arg1 ); Configure(); return; } //////////////////////////////////////// if( 0==strcmp(cmdStr,"sg-adb") ){ arg1 = CliArgByIndex( cli, 1 ); if( !arg1 ) { SvcErr(tsc); return; } gSgCfgAttenDb = atol( arg1 ); Configure(); return; } //////////////////////////////////////// if( 0==strcmp(cmdStr,"sg-get-lo-hz") ){ int dn; arg1 = CliArgByIndex( cli, 1 ); if( !arg1 ) { SvcErr(tsc); return; } dn = (atoi( arg1 ))&1; sprintf( lineBf,"%lld\n", Dp()->Lo(dn)->GetFrequency() ); TcpSvrWrite(tsc,lineBf,strlen(lineBf)); } //////////////////////////////////////// if( 0==strcmp(cmdStr,"sg-mode") ){ int dn; arg1 = CliArgByIndex( cli, 1 ); if( !arg1 ) { SvcErr(tsc); return; } gSgCfgMode = atol( arg1 ); Configure(); } //////////////////////////////////////// if( 0==strcmp(cmdStr,"sg-power-enable") ){ int dn; arg1 = CliArgByIndex( cli, 1 ); if( !arg1 ) { SvcErr(tsc); return; } dn = (atoi( arg1 ))&1; int pwe; arg2 = CliArgByIndex( cli, 2 ); if( !arg1 ) { SvcErr(tsc); return; } pwe = (atoi( arg2 ))&1; Dp()->Lo(dn)->SetPowerDown( !pwe ); } return; }
void Run() { Init(); Dp(); printf("%d\n",dp[M]); }