Dark Assembly is a governing body in the Netherworld. Here sit the senators who take the most important decisions for the player. For example, to expand the range of the shop or to improve certain characteristics of the character the Dark Assembly's approval is needed.
The Dark Assembly consists of n senators. Each of them is characterized by his level and loyalty to the player. The level is a positive integer which reflects a senator's strength. Loyalty is the probability of a positive decision in the voting, which is measured as a percentage with precision of up to 10%.
Senators make decisions by voting. Each of them makes a positive or negative decision in accordance with their loyalty. If strictly morethan half of the senators take a positive decision, the player's proposal is approved.
If the player's proposal is not approved after the voting, then the player may appeal against the decision of the Dark Assembly. To do that, player needs to kill all the senators that voted against (there's nothing wrong in killing senators, they will resurrect later and will treat the player even worse). The probability that a player will be able to kill a certain group of senators is equal to A / (A + B), where A is the sum of levels of all player's characters and B is the sum of levels of all senators in this group. If the player kills all undesired senators, then his proposal is approved.
Senators are very fond of sweets. They can be bribed by giving them candies. For each received candy a senator increases his loyalty to the player by 10%. It's worth to mention that loyalty cannot exceed 100%. The player can take no more than k sweets to the courtroom. Candies should be given to the senators before the start of voting.
Determine the probability that the Dark Assembly approves the player's proposal if the candies are distributed among the senators in the optimal way.
The first line contains three integers n, k and A (1 ≤ n, k ≤ 8, 1 ≤ A ≤ 9999).
Then n lines follow. The i-th of them contains two numbers — bi and li — the i-th senator's level and his loyalty.
The levels of all senators are integers in range from 1 to 9999 (inclusive). The loyalties of all senators are integers in range from 0 to 100(inclusive) and all of them are divisible by 10.
Print one real number with precision 10 - 6 — the maximal possible probability that the Dark Assembly approves the player's proposal for the best possible distribution of candies among the senators.
5 6 100
11 80
14 90
23 70
80 30
153 70
1.0000000000
5 3 100
11 80
14 90
23 70
80 30
153 70
0.9628442962
1 3 20
20 20
0.7500000000
In the first sample the best way of candies' distribution is giving them to first three of the senators. It ensures most of votes.
It the second sample player should give all three candies to the fifth senator.
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int ji[10],b[10],t[10]; int n,k,a; double answer=0.000000; double work(int ro,int B,int pass) { if(ro>n) if(pass+pass>n) return 1; else return (double)a/(a+B); double tans=work(ro+1,B,pass+1)*(t[ro]*10+b[ro])/100; tans+=work(ro+1,B+ji[ro],pass)*(100-(t[ro]*10+b[ro]))/100; return tans; } void dfs(int ro,int su) { if(ro>n) { double tmp; tmp=work(1,0,0); answer=max(tmp,answer); } else { for(int i=0;i<=min(su,(100-b[ro])/10);i++) { t[ro]=i; dfs(ro+1,su-i); } } } int main() { freopen("bribe.in", "r", stdin); freopen("bribe.out", "w", stdout); scanf("%d %d %d",&n,&k,&a); for(int i=1;i<=n;i++) scanf("%d %d",&ji[i],&b[i]); dfs(1,k); printf("%.6lf",answer); return 0; }
样例比较难理解,看代码理解吧!