Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## Re:直接暴力枚举，状态数 6!*5!==720*120==O(7*10^4)

Posted by tasty at 2012-08-23 23:30:35 on Problem 2743
In Reply To:直接暴力枚举，状态数 6!*5!==720*120==O(7*10^4) Posted by:tasty at 2012-08-23 23:29:28
```> rt

Source Code

Problem: 2743  User: tasty
Memory: 1292K  Time: 16MS
Language: C++  Result: Accepted

Source Code
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;
double r,w[10],value[64],ans;
int n;
struct pp
{
double l1,l2;
};
bool vis[64];
int num[64];
void dfs(int state)
{
int i,j,s,p,q;
double l1,l2;
bool have=false;
if(vis[state])
return;
vis[state]=true;
for(i=(state&(state-1));i>0;i=((i-1)&state))
{
j=state^i;
dfs(i);
dfs(j);
for(s=0;s<num[i];s++)
for(p=0;p<num[j];p++)
{
l1=value[j]/(value[i]+value[j]);
l2=value[i]/(value[i]+value[j]);
num[state]++;
}
have=true;
}
if(!have)
{
}
}
int main()
{
int t,i,j,s,p,q;
scanf("%d",&t);
while(t--)
{
scanf("%lf%d",&r,&n);
for(i=0;i<n;i++)
scanf("%lf",&w[i]);
for(i=0;i<(1<<n);i++)
{
value[i]=0;
for(j=0;j<n;j++)
{
if(i&(1<<j))
value[i]+=w[j];
}
}
memset(num,0,sizeof(num));
memset(vis,false,sizeof(vis));
dfs((1<<n)-1);
ans=-1;
for(i=0;i<num[(1<<n)-1];i++)
{
}
printf("%.20f\n",ans);
}
return 0;
}```

Followed by: