zoukankan      html  css  js  c++  java
  • HDU 5045

    http://acm.hdu.edu.cn/showproblem.php?pid=5045

    题意:n个学生m道题,一个n*m的矩阵代表第n个学生解第m题AC的概率,任意两学生做题数差距不能大于1,问AC所有题目概率的最大值

    由于限制条件,所以一定是以n个学生为单位,一轮一轮的做题,直到做m题为止,这样题目就转化为了一个状态压缩dp,当状态为(1<<n)-1的时候清空状态

    dp[i][j]表示AC 前i道题目状态为j的最大值

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <queue>
    #include <map>
    #include <algorithm>
    using namespace std ;
    typedef __int64 ll ;
    double dp[1005][1050] ;// 
    double p[15][1005] ;
    
    int n,m ;
    
    int main()
    {
        int T ;
        scanf("%d",&T) ;
        for(int cas=1 ;cas<=T ;cas++)
        {
            scanf("%d%d",&n,&m) ;
            for(int i=0 ;i<n ;i++)
            {
                for(int j=0 ;j<m ;j++)
                    scanf("%lf",&p[i][j]) ;
            }
            for(int i=0 ;i<1005 ;i++)
                for(int j=0 ;j<1050 ;j++)
                    dp[i][j]=-1.0 ;
            dp[0][0]=0.0 ;
            int sm=(1<<n)-1 ;
            for(int i=0 ;i<m ;i++)
            {
                for(int s=0 ;s<=sm ;s++)
                {
                    if(dp[i][s]<0.0)continue ;
                    int st=0 ;
                    for(int j=0 ;j<n ;j++)
                    {
                        if(!((1<<j)&s))
                        {
                            st=(1<<j)|s ;
                            if(st==sm)st=0 ;
                            dp[i+1][st]=max(dp[i+1][st],dp[i][s]+p[j][i]) ;
                        }
                    }
                }
            }
            double ans=0.0 ;
            for(int i=0 ;i<=sm ;i++)
                ans=max(ans,dp[m][i]) ;
            printf("Case #%d: %.5lf
    ",cas,ans) ;
        }
        return 0 ;
    }
    View Code
  • 相关阅读:
    TCP的初始cwnd和ssthresh
    C/C++ main
    PHP Function
    run bin
    PHP
    LAMP
    PHP MATH
    PHP array sort
    inline
    gcc g++
  • 原文地址:https://www.cnblogs.com/xiaohongmao/p/4008393.html
Copyright © 2011-2022 走看看