题解:UVA12723 Dudu, the Possum
::::info[简化题意]{open}
有一个有
第
最多一次向下
每当到达某一层时,选择一份食物吃掉,得到它提供的卡路里,然后前往下一层。
如果当前层数大于
输出在离开架子前,预期会吸收多少卡路里?
::::
::::info[思路]
我们定义
因为我们初始在第
期望总卡路里等于每一层
::::
::::success[Code]
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define itn int
#define ull unsigned long long
int T;
int n,k;
int main(){
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
cin>>T;
for(int i=1;i<=T;i++){
cin>>n>>k;
vector<double>p(k+1),dp(n+1,0);
dp[1]=1;
for(int i=1;i<=k;i++)cin>>p[i];
double ans=0;
for(int i=1;i<=n;i++){
int l;cin>>l;
double sum=0;
for(int j=1;j<=l;j++){
double c,x;cin>>c>>x;
sum+=c*x;
}
for(int j=1;j<=k&&i-j>0;j++){
dp[i]+=dp[i-j]*p[j];
}
ans+=dp[i]*sum;
}
printf("Case #%d: %.6lf\n",i,ans);
}
return 0;
}
/*
` 4 000 4
44 0 0 44
x x y y x x 44 0 0 44
x x y y x x 4 4 0 0 4 4
x x y y x x 4 4 0 0 4 4
x y y x 4 4 0 0 4 4
x x y y x x 44444 0 0 44444
x x y x x 4 0 0 4
x x y x x 4 000 4
yy
*/
::::
::::info[AI 使用说明]
使用了通义千问进行翻译,并由人工进行简化。
::::