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

RE????达人帮忙看看吧

Posted by gohan at 2007-10-14 19:26:16 on Problem 3413
#include <cstdio>
#include <vector>
using namespace std;
int n;
float maxans=0;
vector<int> ans;
int task[12][3]={0};
void MJ(int times,int mask,vector<int>& seq,int exp,float probability)
{
    float p = probability;
    if(times==n)
    {
        if(probability>maxans)
        {
            maxans=probability;
            ans = seq;
        }
        return;
    }
    for(int i=0;i<n;i++)
    {
        if(!(mask&(1<<i)))
        {
            seq.push_back(i);
            if(exp<task[i][0])p=0;
            else
            if(exp>task[i][1])p=1;
            else{
                if(task[i][1]-task[i][0]==0) while(1);
                p = float((float)exp-(float)task[i][0])/float((float)task[i][1]-(float)task[i][0]);
            }
            if(probability*p>maxans)
            MJ(times+1,mask|(1<<i),seq,exp+task[i][2],probability*p);
            seq.pop_back();
        }
    }
}

int main()
{
    scanf("%d",&n);
    int beginexp=0;
    scanf("%d",&beginexp);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d%d",&task[i][0],&task[i][1],&task[i][2]);
    }
    vector<int> temp;
    MJ(0,0,temp,beginexp,1.0);
    printf("%.3f\n",maxans);
    for(int i=0;i<n;i++)
    {
        if(i==0)
            printf("%d",ans[i]+1);
        else
            printf(" %d",ans[i]+1);
    }
    printf("\n");
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator