Jon and Orbs CodeForces

来源:互联网 发布:创业软件股份 编辑:程序博客网 时间:2024/06/05 14:38

One fine morning, n fools lined up in a row. After that, they numbered each other with numbers from 1 to n, inclusive. Each fool got a unique number. The fools decided not to change their numbers before the end of the fun.

Every fool has exactly k bullets and a pistol. In addition, the fool number i has probability of pi (in percent) that he kills the fool he shoots at.

The fools decided to have several rounds of the fun. Each round of the fun looks like this: each currently living fool shoots at another living fool with the smallest number (a fool is not stupid enough to shoot at himself). All shots of the round are perfomed at one time (simultaneously). If there is exactly one living fool, he does not shoot.

Let’s define a situation as the set of numbers of all the living fools at the some time. We say that a situation is possible if for some integer number j (0 ≤ j ≤ k) there is a nonzero probability that after j rounds of the fun this situation will occur.

Valera knows numbers p1, p2, …, pn and k. Help Valera determine the number of distinct possible situations.

Input
The first line contains two integers n, k (1 ≤ n, k ≤ 3000) — the initial number of fools and the number of bullets for each fool.

The second line contains n integers p1, p2, …, pn (0 ≤ pi ≤ 100) — the given probabilities (in percent).

Output
Print a single number — the answer to the problem.

Example
Input
3 3
50 50 50
Output
7
Input
1 1
100
Output
1
Input
2 1
100 100
Output
2
Input
3 3
0 0 0
Output
1
Note
In the first sample, any situation is possible, except for situation {1, 2}.

In the second sample there is exactly one fool, so he does not make shots.

In the third sample the possible situations are {1, 2} (after zero rounds) and the “empty” situation {} (after one round).

In the fourth sample, the only possible situation is {1, 2, 3}.



dp[i][j]表示i天生产了j种,于是就很容易转移了。

#include<iostream>using namespace std;#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<stdlib.h>#include<vector>#include<queue>#include<deque>#include<map>#include<set>#include<time.h>#define pi(x,y) printf("%d%c",(x),(y));#define pin(x) printf("%d\n",(x));#define si(x) scanf("%d",&(x))#define sii(x,y) scanf("%d%d",&(x),&(y))#define s3(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))#define rep(x,y,z) for(int (x)=(y);(x)<(z);++(x))#define dep(x,y,z) for(int (x)=(y)-1;(x)>=(z);--(x))#define read int TcaseN;scanf("%d",&TcaseN);for(int Tcase=1;Tcase<=TcaseN;++Tcase)#define cls(x,y) memset((x),(y),sizeof((x)));#define pb(x) push_back(x)#define mp(x,y) make_pair((x),(y))#define max3(value_a,value_b,value_c) max(max(value_a,value_b),value_c)#define min3(value_a,value_b,value_c) min(min(value_a,value_b),value_c)#define GT(x) (x)=clock();#define fin(x) freopen(x,"r",stdin);#define fout(x) freopen(x,"w",stdout);///In This You Can Define Long Integer Type#define LONGTYPE long longtypedef LONGTYPE LL;typedef unsigned LONGTYPE ULL;const int maxint=((~((unsigned)(0)))>>1);const LL maxll=((~((unsigned LONGTYPE)(0)))>>1);const int inf=0x3f3f3f3f;const double PI=acos(-1.0);const int N=1005;const int M=N*10;double dp[M][N];int k,q;int main() {#ifdef tangge    clock_t tSTART,tEND,t3;    GT(tSTART);#endif // tangge    /*Input:*/    sii(k,q);    dp[0][0]=1;    for(int i=1;i<M;++i){        for(int j=1;j<=k;++j){            dp[i][j]=dp[i-1][j]*j/k+dp[i-1][j-1]*(k-(j-1))/k;        }    }    int num;    for(int i=1;i<=q;++i){        scanf("%d",&num);        double p1=(num-1e-7)/2000.00;        for(int j=1;j<M;++j){            if(dp[j][k]>=p1){                printf("%d\n",j);break;            }        }    }#ifdef tangge    GT(tEND);    printf("%.8lf\n",(tEND-tSTART)/1000.0);#endif // tangge    return 0;}