• hdu 5389 Zero Escape


    传送门

    Zero Escape

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


    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(1X9), 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=9B=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
    The first line of the input contains a single number T, the number of test cases.
    For each test case, the first line contains three integers nA and B.
    Next line contains n integers idi, describing the identifier of every player.
    T100n105n1061A,B,idi9
     
    Output
    For each test case, output a single integer in a single line, the number of ways that these n players can get into these two doors.
     
    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
     
     
     
    16464431 2016-03-07 10:54:36 Accepted 5389 483MS 6260K 1168 B G++ czy
     
    题解:
    解题:

        比赛的时候是水过的,不得不吐槽下多校的数据真水,听说样例都没过也能A。之前发了错误的题解,实在是抱歉,现在改正了。之前大致思路是对的:

        dp[i][j]=dp[i-1][j]+dp[i-1][tmp](tmp为j-arr[i],若小于等于0,需加9调整)

        dp[i][j]含义为取前i个数字中的若干个,按给定规则,算出来的和为j的方案数

        之前有两个细节没考虑到,

        一是、当前位和我dp[i][j]中的j值相同,那么对应三种情况。

        1.当前位不取,直接取前面dp[i-1][j]的值

        2.当前位取,前面取的是dp[i-1][9]的值(因为加9,不变)

        3.当前位取,前面都不取,此种情况特殊,直接加一即可。

        其实2、3两种情况是一个数分别对应dp[i-1][0]和dp[i-1][9]的特殊情况。

        二是、当a+b的和和sum相同时,最后输出结果的时候,按理说只要输出dp[n][a]就可以了,但是这样会遗漏a中都不取,全都放在b中,而b又刚好和sum相同的情况。

        现在是没有错误了,请放心看微笑

    注意点:

    开始想到dp了,不过傻傻的用了3维dp,结果超时了,没注意到一部分人进了A门,那么剩下的人肯定要进B门,所以第三维可以省掉。

     
    转移方程:
        for(o = 1;o <= n;o++){
            for(i = 0;i <= 9;i++){
                t = (9+i-x[o]) % 9;
                dp[o][i] = (dp[o-1][t] + dp[o-1][i]) %mod;
            }
        }
     
     
    代码:
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <stack>
     6 #include <cctype>
     7 #include <vector>
     8 #include <cmath>
     9 #include <map>
    10 #include <queue>
    11 
    12 #define ll long long
    13 #define N 100005
    14 #define mod 258280327
    15 
    16 using namespace std;
    17 
    18 int T;
    19 int n,a,b;
    20 int x[N];
    21 int dp[N][11];
    22 int ans;
    23 int s;
    24 
    25 int root(int x) {return (x-1)%9+1;}
    26 
    27 void solve()
    28 {
    29     int i,o;
    30     int t;
    31     dp[0][0] = 1;
    32     for(o = 1;o <= n;o++){
    33         for(i = 0;i <= 9;i++){
    34             t = (9+i-x[o]) % 9;
    35             dp[o][i] = (dp[o-1][t] + dp[o-1][i]) %mod;
    36         }
    37     }
    38 }
    39 
    40 int main()
    41 {
    42     //freopen("in.txt","r",stdin);
    43     scanf("%d",&T);
    44     for(int ccnt=1;ccnt<=T;ccnt++){
    45     //while(scanf("%d%s%s",&n,a,b)!=EOF){
    46         scanf("%d%d%d",&n,&a,&b);
    47         memset(dp,0,sizeof(dp));
    48         int i;
    49         s = 0;
    50         for(i = 1;i <= n;i++){
    51             scanf("%d",&x[i]);
    52             s = root(s+x[i]);
    53         }
    54         solve();
    55         ans = 0;
    56         if(root(a+b)==s) ans+=dp[n][a];
    57         else if(a==s) ++ans;
    58         if(b==s) ++ans;
    59         printf("%d
    ",ans%mod);
    60     }
    61     return 0;
    62 }
  • 相关阅读:
    maven工程中dubbo与spring整合
    redis在linux服务器部署
    redis在应用中使用连接不释放问题解决
    redis使用例子
    文件上传和下载(可批量上传)——基础(一)
    Hibernate各种主键生成策略与配置详解
    理解Spring、工厂模式和原始方法的说明以及对Spring的底层实现的理解
    查询文件当前目录
    Spring官网改版后下载
    Mysql事件学习
  • 原文地址:https://www.cnblogs.com/njczy2010/p/5249785.html
Copyright © 2020-2023  润新知