ZOJ 2297 Survival 【状态压缩】

探讨了在《拳皇97》生存模式下使用单一角色连续击败所有对手的算法实现,包括状态压缩技巧和具体代码示例。

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

Survival

Time Limit: 5 Seconds      Memory Limit: 32768 KB

The King of Fighter 97 (KOF97) is an electronic game of wrestling type. Once it was fashionable among youths. The game is amused. However, playing by oneself is not as excited as with friends. Getting bored? Maybe you can alter to the survival mode.

In the survival mode, you play as usual, but under quite unfair conditions: you must use your only character to beat all the other characters and Orichi as well (who is the BOSS)!!! How can you do that? We know that usually we will consume some HP of the character to beat one opponent. Although the character will recover some HP after beating one opponent, the amount of HP recovered is affected by the time you used, so it��s possible that the character lose some HP after one round. What��s worse, if the HP of your character is not enough for you to beat your opponent, you lose!

Given the HP of your character you need to consume and the HP your character will recover if you win for every opponent, you are to determine whether you can clear the game.

NOTE:
1. The initial HP of your character is 100.
2. You can challenge your opponents in any order except that Orichi is always the last one.
3. If your HP falls BELOW zero after any fights (before recovery), you will get your mission failed.4. Your HP should never exceed 100.


Input

There are multiple test cases, which are separated by a blank line. The first line of each test case is a single integer N (1 <= N <= 20), gives the number of opponents you need to beat. The following N �C 1 lines each contain two integers C and R (0 <= C, R <= 100), where C for the HP you need to consume to beat the opponent and R for the HP recovered after you beat the opponent. The last line contains only one integer P (0 <= P <= 100), describing the HP you need to consume to beat Orichi.


Output

For each test case, generate one line of output: if you can clear the game, print "clear!!!" otherwise print "try again" (both without quotations).


Sample Input

3
50 50
40 40
70


Sample Output

clear!!!



典型的状态压缩。


#include<iostream>
 #include<cstring>
 #include<cstdio>
 #include<cmath>
 #include<algorithm>
 using namespace std;
 int dp[1<<21];
 struct node{
    int use;
    int value;
 }t[21];
 int main()
 {
    int n;
    int consume;
    while(cin>>n)
    {
        for(int i=0;i<n-1;i++)
            scanf("%d %d",&t[i].use,&t[i].value);
        cin>>consume;
        memset(dp,-1,sizeof(dp));
        dp[0]=100;
        for(int i=1;i<=((1<<(n-1))-1);i++)
        {
            dp[i]=-1000;
            for(int j=0;(1<<j)-1<=i;j++)
            {
                if(i & (1<<j) && dp[i^(1<<j)]>=t[j].use)
                   {
                       int sum=dp[i-(1<<j)]-t[j].use+t[j].value;
                       if(sum>100)
                         sum=100;
                       if(sum>dp[i])
                         dp[i]=sum;
                   }
            }
        }
        if(dp[(1<<(n-1))-1]>=consume)
            printf("clear!!!\n");
        else
            printf("try again\n");
    }
    return 0;
 }




开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

内容概要:本文档围绕“经济学期刊论文复现:数字化转型能否促进企业的高质量发展”这一核心命题,系统整合了MATLAB与Python编程实现的大量科研案例,聚焦于数字化转型对企业全要素生产率(TFP)及高质量发展影响的实证研究。文档不仅复现了高水平经济学期刊论文中的计量经济模型,如基于中国上市公司数据的数字化转型与生产率关系分析,还深度融合了工程领域的建模技术,涵盖微电网优化、负荷预测、风电光伏不确定性建模、电力系统故障仿真等。同时,提供了智能优化算法(如遗传算法、粒子群优化)、机器学习(LSTM、CNN-BiGRU-Attention)、信号处理、路径规划等多学科交叉的技术资源,构建了一个从理论推导到代码实现的完整科研支持体系,旨在帮助研究者系统掌握论文复现与实证分析的核心方法。; 适合人群:具备一定MATLAB或Python编程基础,从事经济学、管理学、能源系统、智能制造及相关交叉学科研究的研究生、科研人员及高校教师。; 使用场景及目标:①复现经济学顶刊中关于数字化转型与企业高质量发展的实证模型;②学习如何量化数字化转型并构建其对企业绩效的影响评估框架;③掌握基于真实数据的计量经济建模、场景生成与优化调度仿真技术,全面提升科研论文写作与实证研究能力。; 阅读建议:建议读者结合文中提供的代码与数据资源,重点研读“论文复现”与“创新未发表”模块,按照技术路径循序渐进地实现模型复现与拓展。推荐关注“荔枝科研社”公众号及百度网盘链接获取完整资料,系统性地开展学习与科研实践。
下载代码方式:https://pan.quark.cn/s/9de6a9d0b3d8 依据所提供的文件内容,能够推导出此段程序的核心任务在于对一个任意的三位数进行拆解,并且分别呈现该数值的百位、十位及个位部分。随后,我们将对该知识点进行进一步的深入研究。 ### 一、程序功能说明 #### 1. 接收任意一个三位数输入 程序起始阶段运用`scanf`函数来获取用户输入的一个整数。为确保输入内容确实为一个三位数,在实际应用场景中通常需要嵌入验证机制来保障输入的有效性。然而,在本示例情形下,该环节被简化处理,预设用户总会准确输入一个三位数。 #### 2. 实施数字的拆分并提取各位置数值 程序借助一系列数学计算来对三位数进行拆分,将其转化为百位、十位和个位三个独立的构成部分。具体而言,通过除法和取模运算完成了这一过程。 #### 3. 展示各位置上的数值 程序运用`printf`函数来输出原始数值以及各个位上的数值。需要留意的是,代码中的输出部分似乎存在一些混淆,存在语法上的错误,例如多余的`printf`语句和乱码字符等问题。 ### 二、核心代码分析 #### 1. 数字拆分逻辑 ```c a[0] = n / 1000; // 提取千位数,但鉴于题目要求是三位数,此处应为百位数 a[1] = n % 1000 / 100; // 提取百位数 a[2] = n % 1000 % 100 / 10; // 提取十位数 a[3] = n % 1000 % 100 % 10; // 提取个位数 ``` 这段代码通过一连串的除法和取模运算,成功地将输入的数字n拆分为百位、十位和个位三个独立的构成部分,...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值