Topcoder SRM 687 Div2

Source: Internet
Author: User
Tags bitset cmath

Topcoder SRM 687 Div2
By number: 2
250:

#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>using namespace STD;classQuorum { Public:intCount vector <int>,int);};intQuorum::count ( vector <int>Arrintk) {sort (Arr.begin (), Arr.end ());intres =0; for(inti =0; I < min (k, (int) arr.size ()); i++) Res + = Arr[i];returnRes;} <%:testing-code%>//powered by [Kawigiedit] 2.0!

500:
Plus a vector to backtrack.

#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>using namespace STD;classquacking { Public:intQuack (string);};stringstr ="Quack";intQuacking::quack (strings) {intn = s.size ();intres =0;intvis[ the]; for(inti =0; I < n; i++) {//printf ("I =%d\n", i);        if(Vis[i] = =1)Continue;Else if(S[i]! =' Q ')return-1;intnum =0; vector<int>Rev; for(intj = i; J < N; J + +) {if(Vis[j] = =1)Continue;if(S[j] = = Str[num]) {num++, vis[j] =1, Rev.push_back (j);//, printf ("%d", j);}if(num = =5) {rev.clear (); num =0; }        }//Puts ("");         for(intj =0; J < (int) Rev.size (); J + +) Vis[rev[j]] =0;    res++; } for(inti =0; I < n; i++)if(Vis[i] = =0)return-1;returnRes;} <%:testing-code%>//powered by [Kawigiedit] 2.0!

1000:
Shot to death is the probability of DP
After conversion, it is found that the original expression is F (p,k) indicates that the first k-1 days are not completed, the probability of K-day completion
Well, the probability of completing every day is 1/p.
DP[I][J] Indicates the arrival (I,J) state, the first task consumes less time than the first task's probability
Initialize dp[i][0] = 0, dp[0][i!=0] = 1

#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>using namespace STD;classQueueing { Public:DoubleProbfirst (int,int,int,int);};Const intMAXN = ++5;DoubleDP[MAXN][MAXN];DoubleQueueing::p Robfirst (intLen1,intLen2,intP1,intP2) {DoubleQ1 =1.0/ (1.0* p1);DoubleQ2 =1.0/ (1.0* p2); for(inti =0; I <= len1; i++) { for(intj =0; J <= Len2; J + +) {if(J = =0) Dp[i][j] =0;Else if(i = =0) Dp[i][j] =1;Else{DoubleTemp1 = (Q1) * (Q2) * Dp[i-1][j-1];DoubleTemp2 = (1-Q1) * Q2 * DP[I][J-1];DoubleTemp3 = (Q1) * (1-Q2) * Dp[i-1][J]; DP[I][J] = (Temp1 + temp2 + Temp3)/(1.0- (1-Q1) * (1-Q2)); }        }    }returnDP[LEN1][LEN2];} <%:testing-code%>//powered by [Kawigiedit] 2.0!

Topcoder SRM 687 Div2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.