【玲珑杯 1053】【概率DP】Gemstone digger

传送门:http://www.ifrog.cc/acm/problem/1053

思路:

dp[i][j]表示前ii个矿,得到jj个宝石,不会死亡的最大概率。
转移方程:
dp[i][j]=max(dp[i1][j],dp[i1][jai](1pi))

然后找不会死亡概率>0.19的最大宝石数即可。


代码:

#include <iostream>
#include <stdio.h> 
#include <algorithm>
#include <string.h>
using  namespace  std;

#define mst(ss,b) memset(ss,b,sizeof(ss));
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rrep(i,k,n) for(int i=k;i>=n;i--)

template<class T> void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
    for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
    F && (num=-num);
}
const int N=1e5+10;
const double eps=1e-12;//double不能直接比较

int a[110];
double p[N], dp[110][50010];

int  main(){
  int T;
  read(T);
  while(T--){
    int n, sum=0;
    read(n);
    rep(i, 1, n)read(a[i]), sum += a[i];
    rep(i, 1, n)scanf("%lf", &p[i]);

    mst(dp, 0);//memset可以给double类型数组赋值

    rep(i, 0, n)dp[i][0] = 1.0;

    rep(i, 1, n){
      rep(j, 0, sum){
        dp[i][j] = dp[i - 1][j];
        if(j - a[i] >= 0)
          dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i]] * (1.0 - p[i]));
      }
    }
    int ans;
    rrep(j, sum, 1)if(dp[n][j] - 0.19 > eps){
      ans = j;
      break;
    }
    printf("%d\n", ans);
  }
  return 0;
}

描述:

1053 - Gemstone digger

Time Limit:1s Memory Limit:64MByte

Submissions:134Solved:42

DESCRIPTION

A gemstone (also called a gem, fine gem, jewel, precious stone or semi-precious stone) is a piece of mineral crystal which, in cut and polished form, is used to make jewelry or other adornments. However, certain rocks (such as lapis lazuli) or organic materials that are not minerals (such as amber or jet) are also used for jewelry and are therefore often considered to be gemstones as well. Most gemstones are hard, but some soft minerals are used in jewelry because of their luster or other physical properties that have aesthetic value. Rarity is another characteristic that lends value to a gemstone. Apart from jewelry, from earliest antiquity engraved gems and hardstone carvings, such as cups, were major luxury art forms. A gem maker is called a lapidary or gemcutter; a diamond worker is a diamantaire.You are a gemstone digger . There are nn mines. In each mine you will get a certain number of gems, but there is a certain probability that you will die.If your probability of death is0.81≥0.81 , you will be considered to must die. Ensuring that the probabilities are independent of each other. In the case you do not die, how many gemstones can you at most get?

INPUT
There are multiple test cases.The first line is a number T (T  10 ≤10), which means the number of cases.For each case, a integers n(1n100)n(1≤n≤100)..next line contain nn integers ai(0<=ai<=500)ai(0<=ai<=500) that represent the number of gemstone ithi′th mine has.next line contain nn real number pi(0<=pi<=1)pi(0<=pi<=1) that represent the probability of death in the ithi′th mine.For each real number, there are at most 2 digits after the decimal dot.
OUTPUT
one line --- the number of gemstone you can at most get.
SAMPLE INPUT
131 2 30.5 0.3 0.9
SAMPLE OUTPUT
3

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> -<properties> <entry key="app_preset_prof_preset_name">NewAESUtil (1) Launch Configuration</entry> <entry key="app_preset_prof_preset_filter_s"/> <entry key="app_preset_prof_preset_filter_p">com.tool.Document.*, com.tool.ModerateTask.*, com.tool.PanelDisplay.*, com.tool.PlayerKill.*, com.tool.Stall.*, com.tool.btn.*, com.tool.image.*, com.tool.pet.*, com.tool.role.*, com.tool.tcp.*, com.tool.time.*, come.tool.BangBattle.*, come.tool.Fighting.*, come.tool.JDialog.*, come.tool.Scene.*, come.tool.handle.*, come.tool.map.*, org.cbg.bean.*, org.cbg.btn.*, org.cbg.control.*, org.cbg.entity.*, org.cbg.frame.*, org.cbg.mouslisten.*, org.cbg.panel.*, org.cbg.until.*, org.come.Frame.*, org.come.Jpanel.*, org.come.action.*, org.come.bean.*, org.come.control.*, org.come.daily.*, org.come.entity.*, org.come.good.*, org.come.login.*, org.come.model.*, org.come.mouslisten.*, org.come.npc.*, org.come.socket.*, org.come.starcard.*, org.come.strength.*, org.come.summonequip.*, org.come.test.*, org.come.thread.*, org.come.until.*, org.come.view.*, org.gemstone.btn.*, org.gemstone.mouseListener.*, org.gemstone.panel.*, org.lottery.btn.*, org.lottery.frame.*, org.lottery.mouseListener.*, org.lottery.panel.*, org.skill.btn.*, org.skill.frame.*, org.skill.panel.*, org.soaring.btn.*, org.soaring.panel.*, org.wing.btn.*, org.wing.mouseListener.*, org.wing.panel.*</entry> <entry key="app_preset_prof_preset_alloc_p">10</entry> <entry key="app_preset_"/> <entry key="app_preset_prof_preset_samplingRefreshRate_s">1000</entry> <entry key="app_preset_prof_preset_stacks_p">false</entry> <entry key="app_preset_prof_preset_roots_p">com.tool.Document.** com.tool.ModerateTask.** com.tool.PanelDisplay.** com.tool.PlayerKill.** com.tool.Stall.** com.tool.btn.** com.tool.image.** com.tool.pet.** com.tool.role.** com.tool.tcp.** com.tool.time.** come.tool.BangBattle.** come.tool.Fighting.** come.tool.JDialog.** come.tool.Scene.** come.tool.handle.** come.tool.map.** org.cbg.bean.** org.cbg.btn.** org.cbg.control.** org.cbg.entity.** org.cbg.frame.** org.cbg.mouslisten.** org.cbg.panel.** org.cbg.until.** org.come.Frame.** org.come.Jpanel.** org.come.action.** org.come.bean.** org.come.control.** org.come.daily.** org.come.entity.** org.come.good.** org.come.login.** org.come.model.** org.come.mouslisten.** org.come.npc.** org.come.socket.** org.come.starcard.** org.come.strength.** org.come.summonequip.** org.come.test.** org.come.thread.** org.come.until.** org.come.view.** org.gemstone.btn.** org.gemstone.mouseListener.** org.gemstone.panel.** org.lottery.btn.** org.lottery.frame.** org.lottery.mouseListener.** org.lottery.panel.** org.skill.btn.** org.skill.frame.** org.skill.panel.** org.soaring.btn.** org.soaring.panel.** org.wing.btn.** org.wing.mouseListener.** org.wing.panel.** </entry> <entry key="profiler.settings.instrument.empty.methods">false</entry> <entry key="myeclipse.profiling.mode">0</entry> <entry key="profiler.settings.istrument.getter.setter.methods">false</entry> <entry key="app_preset_prof_preset_samplingRate_s">100</entry> <entry key="app_preset_prof_preset_filterMode_s">true</entry> <entry key="app_preset_prof_preset_selector"/> <entry key="app_preset_prof_preset_refreshRate_s">1000</entry> <entry key="app_preset_prof_preset_runnables_p">true</entry> <entry key="app_preset_prof_preset_filterMode_p">false</entry> <entry key="app_preset_prof_preset_memoryMode_p">true</entry> </properties>
03-20

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值