2162: Inuyasha And the Monsters

Inuyasha和Kagome计划清除一系列宫殿中的怪物。这些宫殿从南到北排列成一条直线,他们只能从南向北前进。每个宫殿里藏有一定数量的怪物,如果在当前宫殿杀死的怪物数量超过前方宫殿的数量,则前方的怪物会逃跑。任务是帮助Inuyasha尽可能多地消灭怪物。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 2162: Inuyasha And the Monsters


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
5s8192K573184Standard
Inuyasha and Kagome, do you hear of them?

Now, they want to kill a great many of monsters. Those monsters hide in several palaces. The palaces are built in a straight line from the south to the north. they must go from the south to the north and can only move straight ahead. That is to say, they can't go from north to the south at any time.

But there is another problem. All the monsters in front of the current palace will escape immedietely if the number of monsters they killed in the current palace is more than the ones of those palaces.

Surely Inuyasha wants to kill as many monsters as he can. Can you help him?

Note: Once they determine to kill the monsters in a palace, they must kill them all.

Input

The input file contains one or more test cases, followed by a line containing the number 0 that signals the end of the file. Each test case consists of two lines.the first line contains a single integer M(M<10000), which indicates the number of the palaces; the second line contains M integers, which are the number of the monsters in the palaces, from south to north. You may assume that all numbers are less than 2^31.

Output

The output for every case begins with a line containing "Case #k:", where k is the number of the test case starting from 1. Then print a single integer which is the number of the monsters they has killed. It is also in a single line. Print a blank line between every two cases.

Sample Input

5
1 2 3 4 5
5
4 5 3 1 2
0

Sample Output

Case #1:
15

Case #2:
9

 

Problem Source: chihao

#include<stdio.h>
int dp[10000];
int a[10000];
int main()
{
    int n,i,j;
    int l=1;
    int m=0;
    while(scanf("%d",&n)==1&&n)
    {
        if(m==0) m++;
        else printf("/n");
        printf("Case #%d:/n",l++);
        for(i=0;i<n;i++){scanf("%d",&a[i]);}
        dp[0]=a[0];
        for(i=1;i<n;i++)
        {
            dp[i]=a[i];
            for(j=0;j<i;j++)
            {
                if(a[i]>=a[j]&&dp[i]<dp[j]+a[i]) dp[i]=dp[j]+a[i];
            }
        }
        int  max=0;
        for(i=0;i<n;i++)
        {
            if(dp[i]>max) max=dp[i];
        }
        printf("%d/n",max);
    }
    return 0;
}

在安装PyTorch之前,你需要创建一个专门的虚拟环境来进行安装。你可以使用以下命令来创建一个名为pytorch的虚拟环境: ``` conda create -n pytorch python=3.6 ``` 然后,你可以使用以下命令激活pytorch环境: ``` conda activate pytorch ``` 接下来,你可以使用以下命令安装PyTorch: ``` conda install pytorch torchvision torchaudio cudatoolkit=11.3 ``` 请注意,上述命令是通过conda安装PyTorch,这是推荐的方法。安装完成后,你可以使用以下命令来验证PyTorch是否成功安装: ``` python -c "import torch; print(torch.cuda.is_available())" ``` 这将输出一个布尔值,表示你的系统是否支持CUDA加速。如果输出为True,则表示PyTorch安装成功。希望这可以帮助到你。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [1.PyTorch环境的配置及安装(Configuration and Installation of PyTorch)](https://blog.youkuaiyun.com/weixin_43866408/article/details/124685555)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [PyTorch深度学习快速入门教程【小土堆】 学习笔记](https://blog.youkuaiyun.com/Inuyasha_1314/article/details/124958908)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值