首页 > 其他分享 >HDU 5389 Zero Escape(DP + 滚动数组)

HDU 5389 Zero Escape(DP + 滚动数组)

时间:2023-04-21 12:07:11浏览次数:47  
标签:HDU door get int 5389 into players Zero include


Zero Escape


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 864    Accepted Submission(s): 438



Problem Description


Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi (you may hear about ever17?) and developed by Chunsoft.

Stilwell is enjoying the first chapter of this series, and in this chapter digital root is an important factor. 

This is the definition of digital root on Wikipedia:
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
For example, the digital root of  65536 is  7, because  6+5+5+3+6=25 and  2+5=7.

In the game, every player has a special identifier. Maybe two players have the same identifier, but they are different players. If a group of players want to get into a door numbered  X(1≤X≤9), the digital root of their identifier sum must be  X.
For example, players  {1,2,6} can get into the door  9, but players  {2,3,3} can't.

There is two doors, numbered  A and  B. Maybe  A=B, but they are two different door.
And there is  n players, everyone must get into one of these two doors. Some players will get into the door  A, and others will get into the door  B.
For example: 
players are  {1,2,6},  A=9,  B=1
There is only one way to distribute the players: all players get into the door  9. Because there is no player to get into the door  1, the digital root limit of this door will be ignored.

Given the identifier of every player, please calculate how many kinds of methods are there,  mod 258280327.


 



Input


T, the number of test cases.
For each test case, the first line contains three integers  n,  A and  B.
Next line contains  n integers  idi, describing the identifier of every player.
T≤100,  n≤105,  ∑n≤106,  1≤A,B,idi≤9


 



Output


n


 



Sample Input


4 3 9 1 1 2 6 3 9 1 2 3 3 5 2 3 1 1 1 1 1 9 9 9 1 2 3 4 5 6 7 8 9


 



Sample Output


1 0 10 60


 



Author


SXYZ


 



Source


2015 Multi-University Training Contest 8


 





   题意:给出n个人的id,有两个门,每个门有一个标号,我们记作a和b,现在我们要将n个人分成两组,进入两个门中,使得两部分人的标号的和(迭代的求,直至变成一位数)分别等于a和b,问有多少种分法,(可以所有的人进入一个门)。


点击打开链接


pt = j - p[i];

状态转移方程: dp[i][j] = dp[i-1][j] + dp[i-1][pt];

两种处理方法:



#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

const int N = 100001;
const int mod =  258280327;
int dp[N][10];
int n,a,b;
int p[N];

int num(int xx,int yy)
{
    int t = xx + yy;
    if(t%9 == 0)
    {
        return 9;
    }
    return t%9;
}

int pnum(int xx,int yy)
{
    int tt = xx - yy;
    if(tt%9 == 0)
    {
        return 9;
    }
    if(tt%9<0)
    {
        return 9+(tt%9);
    }
    return tt%9;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int sum = 0;
        scanf("%d%d%d",&n,&a,&b);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&p[i]);
            sum = num(sum,p[i]);
        }
        memset(dp,0,sizeof(dp));
        dp[0][0] = 1;
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<=9;j++)
            {
                dp[i][j] += dp[i-1][j];
                dp[i][j] = dp[i][j]%mod;
                int pt = pnum(j,p[i]);
                if(pt == 9)
                {
                    dp[i][j] += max(dp[i-1][0],dp[i-1][9]);
                }
                else
                {
                    dp[i][j] += dp[i-1][pnum(j,p[i])];
                }
                dp[i][j] = dp[i][j]%mod;
            }
        }
        int ans = 0;
        if(num(a,b) == sum)
        {
            ans = dp[n][a];
            if(a == sum)
            {
                ans--;
            }
        }
        if(a == sum)
        {
            ans++;
        }
        if(b == sum)
        {
            ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}







#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

const int N = 100001;
const int mod =  258280327;
int dp[N][10];
int n,a,b;
int p[N];

int num(int xx,int yy)
{
    int t = xx + yy;
    if(t%9 == 0)
    {
        return 9;
    }
    return t%9;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int sum = 0;
        scanf("%d%d%d",&n,&a,&b);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&p[i]);
            sum = num(sum,p[i]);
        }
        memset(dp,0,sizeof(dp));
        dp[0][0] = 1;
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<=9;j++)
            {
                int pt = num(j,p[i]);
                dp[i][j]+=dp[i-1][j];
                dp[i][pt]+=dp[i-1][j];
                dp[i][j]%=mod;
                dp[i][pt]%=mod;
            }
        }
        int ans = 0;
        if(num(a,b) == sum)
        {
            ans = dp[n][a];
            if(a == sum)
            {
                ans--;
            }
        }
        if(a == sum)
        {
            ans++;
        }
        if(b == sum)
        {
            ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}






标签:HDU,door,get,int,5389,into,players,Zero,include
From: https://blog.51cto.com/u_14834528/6212413

相关文章

  • HDU1873 看病要排队
    E- 看病要排队TimeLimit:1000MS     MemoryLimit:32768KB     64bitIOFormat:%I64d&%I64uDescription看病要排队这个是地球人都知道的常识。不过经过细心的0068的观察,他发现了医院里排队还是有讲究的。0068所去的医院有三个医生(汗,这么......
  • HDU 1114 Piggy-Bank
    F- Piggy-BankTimeLimit:1000MS     MemoryLimit:32768KB     64bitIOFormat:%I64d&%I64uSubmit StatusDescriptionBeforeACMcandoanything,abudgetmustbepreparedandthenecessaryfinancialsupportobtained.Themaininc......
  • HDU 1869 六度分离
    六度分离TimeLimit:1000MS     MemoryLimit:32768KB     64bitIOFormat:%I64d&%I64uSubmit Status Practice HDU1869Description1967年,美国著名的社会学家斯坦利・米尔格兰姆提出了一个名为“小世界现象(smallworldphenom......
  • HDU 1527 取石子游戏(博弈论)
    取石子游戏TimeLimit:2000/1000MS(Java/Others)    MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):3717    AcceptedSubmission(s):1868ProblemDescription有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有......
  • 2020CVPR_Zero-Reference Deep Curve Estimation for Low-Light Image Enhancement
    1.motivation收到图像编辑软件的启发2. Contribution(1)无监督(2)设计图像高阶曲线适应适合像素级映射,通过迭代自身(3)设计了四个无参考损失函数3.Network 3.1DCE-NetDCE-Net:是由6个Conv2D(3x3)+relu,分别输出为x1,x2, x3,x4,x5,x6,最后的卷积由Conv2d(3x3)+tan激......
  • cocoapods Xcode 14.3 Archive Command PhaseScriptExecution failed with a nonzero
    Xcode升级到14.3进行  Archive CommandPhaseScriptExecutionfailedwithanonzeroexitcode解决方法Xcode搜索 source="$(readlink-f"${source}")"将 source="$(readlink-f"${source}")"改为 source="$(readlink-f"......
  • gozero的指令
    快速创建api服务在当前目录下会新建一个xxx目录goctlapinewxxx根据api文件生成api服务goctlapigo-apixxx.api-dir.根据API文件生成markdown文档#api文件需要配合@doc使用,比如#serviceuser-api{# @doc"用户登录"# @handlerlogin# post/user/login(Lo......
  • python报错:divide by zero encountered in log
    原因:数字太小的原因,溢出,计算过程中出现-inf,再做其他运算,结果还是-inf。当概率很小时,取对数后结果趋于负无穷大解决:改变浮点数的精度参考:(51条消息)RuntimeWarning:dividebyzeroencounteredinlog错误解决_旅途中的宽~的博客-CSDN博客......
  • Value targets in off-policy AlphaZero: a new greedy backup
    发表时间:2021文章要点:这篇文章给AlphaZero设计了一个新的valuetargets,AlphaZerowithgreedybackups(A0GB)。AlphaZero的树里面有探索,而value又是所有结果的平均,所以并不准确。而选动作也是依概率选的,但真正测试的时候是选的访问次数最多的动作,所以这个方法是off-policy,也会......
  • kuangbin专题一 简单搜索 石油储备(HDU-1241)
    OilDepositsTimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)ProblemDescriptionTheGeoSurvCompgeologicsurveycompanyisresponsiblefordetectingundergroundoildeposits.GeoSurvCompworkswithonelargerectangula......