HDU 1203 I NEED A OFFER!

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1203

#include <iostream>
using namespace std;
double dp[10010]={0};
int ans;
void ZeroOnPack(int cost,double weight,int V,double P)
{
    for(int i=V;i>=cost;i--)
    {
        dp[i] = max(dp[i],dp[i-cost]*(1-weight));
        if(dp[i]>=1-P&&ans<i)
        {
            ans = i;
        }
        //cout<<"可取"<<i<<"总钱"<<V<<" "<<dp[i]<<endl;
    }
}
int main(int argc, const char *argv[])
{
    int T;
    //freopen("input.txt","r",stdin);
    cin>>T;
    while(T--)
    {
        ans = 0;
        double P;
        int N;
        int V = 0;
        memset(dp,0,sizeof(dp));
        dp[0]=1;
        cin>>P>>N;
        for(int i=0;i<N;i++)
        {
            float weight;
            int val;
            cin>>val>>weight;
            V+=val;
            ZeroOnPack(val,weight,V,P);
        }
        cout<<ans<<endl;
    }
    return 0;
}

 

posted @ 2013-09-21 21:50  Destino74  阅读(94)  评论(0编辑  收藏  举报