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

本文介绍了一个基于概率的游戏生存模拟算法,通过分析每个玩家的射击命中率,在限定的轮次内预测可能的生存状态组合。

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.

Examples
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}.


题目大意:


给你N个人,以及要进行K轮游戏,每个人都有一把枪,每个人一开始都将抢指向在场上编号最小的那个人身上,编号最小的那个人将枪口指向编号次小的那个人身上。

现在已知每个人打中的概率,问K轮内,会有几种存活情况出现。


思路:


特征类Dp,寻找问题特征,问题的焦点在于编号最小和次小的两个人身上,那么我们设定Dp【i】【j】表示此时场上剩下的人编号最小的人是i,次小的人是j的情况发生的最早轮数.

那么考虑对于这两个人的四种情况:

①i死了,j没有死。那么需要满足的条件有:从j编号开始到n编号,打死i的最大概率应>0.同时pi<100.

Dp【j】【j+1】=min(Dp【j】【j+1】,dp【i】【j】+1);

②i死了,j也死了。那么需要满足的条件有:从j编号开始到n编号,打死i的最大概率应>0.同时pi>0.

Dp【j+1】【j+2】=min(Dp【j+1】【j+2】,dp【i】【j】+1);

③i没死,j死了。那么需要满足的条件有:从j编号开始到n编号,打死i的最大概率应<100.同时pi>0.

Dp【i】【j+1】=min(Dp【i】【j+1】,dp【i】【j】+1);

④i没死,j也没死。那么没有继续转移下去的意义。


那么ans=sum(dp【i】【j】<=k);

注意初始化以及最终剩余1个人、两个人的情况。


Ac代码:

#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int p[5000];
int dp[3005][3005];
int back[3005];
int main()
{
    int n,k;
    while(~scanf("%d%d",&n,&k))
    {
        memset(back,0,sizeof(back));
        memset(p,0,sizeof(p));
        for(int i=1;i<=3003;i++)
        {
            for(int j=1;j<=3003;j++)
            {
                dp[i][j]=0x3f3f3f3f;
            }
        }
        for(int i=1;i<=n;i++)scanf("%d",&p[i]);
        for(int i=n;i>=1;i--)
        {
            if(i==n)back[i]=p[i];
            else back[i]=max(back[i+1],p[i]);
        }
        dp[1][2]=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                if(back[j]>0&&p[i]<100)dp[j][j+1]=min(dp[j][j+1],dp[i][j]+1);
                if(back[j]>0&&p[i]>0)dp[j+1][j+2]=min(dp[j+1][j+2],dp[i][j]+1);
                if(back[j]<100&&p[i]>0)dp[i][j+1]=min(dp[i][j+1],dp[i][j]+1);
            }
        }
        int output=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n+1;j++)
            {
                if(dp[i][j]<=k)output++;
            }
        }
        if(dp[n+1][n+2]<=k)output++;
        printf("%d\n",output);
    }
}








当前提供的引用内容并未提及关于Codeforces比赛M1的具体时间安排[^1]。然而,通常情况下,Codeforces的比赛时间会在其官方网站上提前公布,并提供基于不同时区的转换工具以便参赛者了解具体开赛时刻。 对于Codeforces上的赛事而言,如果一场名为M1的比赛被计划举行,则它的原始时间一般按照UTC(协调世界时)设定。为了得知该场比赛在UTC+8时区的确切开始时间,可以遵循以下逻辑: - 前往Codeforces官网并定位至对应比赛页面。 - 查看比赛所标注的标准UTC起始时间。 - 将此标准时间加上8小时来获取对应的北京时间(即UTC+8)。 由于目前缺乏具体的官方公告链接或者确切日期作为依据,无法直接给出Codeforces M1比赛于UTC+8下的实际发生时段。建议定期访问Codeforces平台查看最新动态更新以及确认最终版程表信息。 ```python from datetime import timedelta, datetime def convert_utc_to_bj(utc_time_str): utc_format = "%Y-%m-%dT%H:%M:%SZ" bj_offset = timedelta(hours=8) try: # 解析UTC时间为datetime对象 utc_datetime = datetime.strptime(utc_time_str, utc_format) # 转换为北京时区时间 beijing_time = utc_datetime + bj_offset return beijing_time.strftime("%Y-%m-%d %H:%M:%S") except ValueError as e: return f"错误:{e}" # 示例输入假设某场Codeforces比赛定于特定UTC时间 example_utc_start = "2024-12-05T17:35:00Z" converted_time = convert_utc_to_bj(example_utc_start) print(f"Codeforces比赛在北京时间下将是:{converted_time}") ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值