Codeforces 369D. Valera and Fools

原创 2013年12月01日 20:55:52


D. Valera and Fools
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
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}.


 概率都是假的,只有0,100,其它 三种情况。。。。

每一轮,后面的都打第一个,第一个回头打第二个。。。。只要记录开头的两个就可以了


#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=4000;

bool vis[maxn][maxn];
int n,k,p[maxn],sp[maxn],ans=0;

void dfs(int A,int B,int t)
{
    if(vis[A][B]) return ;
    vis[A][B]=true; ans++;
    if(t==k||B>n) return;
    int p1=p[A],p2=sp[B];
    if(p1)
    {
        if(p2) dfs(B+1,B+2,t+1);
        if(p2!=100) dfs(A,B+1,t+1);
    }
    if(p1!=100&&p2) dfs(B,B+1,t+1);
}

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",p+i);
    for(int i=n;i>=1;i--) sp[i]=max(sp[i+1],p[i]);
    dfs(1,2,0);
    printf("%d\n",ans);
    return 0;
}




版权声明:来自: 码代码的猿猿的AC之路 http://blog.csdn.net/ck_boss

相关文章推荐

Codeforces 369D Valera and Fools【思维+dp】

D. Valera and Fools time limit per test 1 second memory limit per test 256 megabytes inpu...

Codeforces Round #216_div2_D.Valera and Fools

近些日子以来总觉得编程水平没怎么提升,这学期开始虽然每周有四场的队内训练赛,但几个月下来感觉收获不大。想想,还是以刷题的方式来学习吧。每天刷个一两题,然后写写题解。一味的打比赛打比赛被逼的很紧但是却没...

Codeforces Round #216_div2_D.Valera and Fools

这一题主要是DP还是好想的。。不过我只能推出模糊的DP方程。看了一下别人的解法。转载请注明出处http://blog.csdn.net/moedane开始说题。 传送门 http://codefor...

CodeForces 369C. Valera and Elections

C. Valera and Elections time limit per test 1 second memory limit per test 256 megabytes...

Codeforces 369C Valera and Elections【思维+Dfs】

C. Valera and Elections time limit per test 1 second memory limit per test 256 megabytes ...

Codeforces 369E Valera and Queries【逆向思维+离线+树状数组】好题!好题!好题!

E. Valera and Queries time limit per test 2 seconds memory limit per test 512 megabytes i...

Codeforces 362D Fools and Foolproof Roads【并查集+优先队列+思维】

D. Fools and Foolproof Roads time limit per test 1 second memory limit per test 256 megabyte...

Codeforces Round #252 (Div. 2)441D. Valera and Swaps

题目连接:http://codeforces.com/contest/441/problem/D

CF 369E - Valera and Queries(树状数组)

题意:给出n
  • qian99
  • qian99
  • 2014年09月03日 08:45
  • 471

codeforces 192E Fools and Roads

给你一棵树,然后有m个操作,每个操作有两个数 a  b,表示给从a到b的简单路径上的边权都加1,最后要你输出每条边的边权 解法1:dfs 用树链剖分做的话就是很裸的题目了,但是这道题没有让你对路径...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces 369D. Valera and Fools
举报原因:
原因补充:

(最多只允许输入30个字)