Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstring>
- #define cero 10000
- using namespace std;
- int x,y,z,h;
- int mat[20010][22];
- void Leer(){
- string s;
- cin>>s;
- int i=0;
- while (s[i]!='d')
- i++;
- x=0;
- for (int j=0;j<i;j++)
- x=x*10+(s[j]-'0');
- int len=s.size(),ant=i+1,sign=1;
- while ((i<len) && (s[i]!='+')&&(s[i]!='-'))
- i++;
- y=0;
- for (int j=ant;j<i;j++)
- y=y*10+(s[j]-'0');
- z=0;
- if (i==len)
- return;
- ant=i+1;
- if (s[i]=='-')
- sign=-1;
- for (int j=ant;j<len;j++)
- z=z*10+(s[j]-'0');
- z=z*sign;
- }
- double Procesar(){
- memset(mat,0,sizeof(mat));
- int aux=0;
- for (int i=1+z;i<=(y+z);i++){
- mat[cero+i][1]=1;
- if ((1==x)&&(i<h))
- aux+=mat[cero+i][1];
- if ((1==x)&&(i==h))
- return ((pow(y,x)-aux)/pow(y,x));
- }
- for (int i=2;i<=x;i++){
- for (int j=(i+z);j<=((i*y)+z);j++){
- mat[cero+j][i]=0;
- for (int k=1;k<=y;k++)
- mat[cero+j][i]+=mat[cero+j-k][i-1];
- if ((i==x)&&(j<h)){
- aux+=mat[cero+j][i];
- }
- if ((i==x)&&(j==h))
- break;
- }
- }
- return ((pow(y,x)-aux)/pow(y,x));
- }
- int main() {
- int t,s;
- double max,ans;
- cin>>t;
- for (int i=1;i<=t;i++){
- cin>>h>>s;
- max=0;
- for (int j=0;j<s;j++){
- Leer();
- ans=Procesar();
- if (ans>max)
- max=ans;
- }
- printf("Case #%d: %.6f\n",i,max);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment