标签:int mic ++ color using pre eof can include
dp[k]用类似于低配版的这道题的做法求出,如下;
然后就从k逆推到0就好了
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int MX = 105; 4 double dp[MX]; 5 int x[MX]; 6 int main(){ 7 int T,n,k; 8 scanf("%d",&T); 9 for(int cas=1;cas<=T;cas++){ 10 memset(dp,0,sizeof(dp)); 11 scanf("%d%d",&n,&k); 12 int a=0,b; 13 double sum1=0,sum2=0; 14 for(int i=0;i<n;i++) { 15 scanf("%d",&x[i]); 16 if(x[i]>0) {sum1+=x[i];a++;} 17 else sum2+=abs(x[i]); 18 } 19 if(a==0){ 20 printf("Case %d: -1\n",cas); 21 continue; 22 } 23 b=n-a; 24 if(a) sum1/=a; 25 if(b) sum2/=b; 26 k=min(k,b); 27 dp[k]=sum1+(b-k)*sum2/a; 28 for(int i=k-1;i>=0;i--){ 29 dp[i]=(dp[i+1]+sum2)*(b-i); 30 dp[i]+=sum1*a; 31 dp[i]/=n-i; 32 } 33 printf("Case %d: %.7f\n",cas,dp[0]); 34 } 35 return 0; 36 }
标签:int mic ++ color using pre eof can include
原文地址:https://www.cnblogs.com/pangbi/p/11613992.html