zoukankan      html  css  js  c++  java
  • Manthan, Codefest 17

    A. Tom Riddle's Diary
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.

    He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.

    Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).

    Input

    First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list.

    Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.

    Output

    Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.

    You can print each letter in any case (upper or lower).

    Examples
    input
    6
    tom
    lucius
    ginny
    harry
    ginny
    harry
    output
    NO
    NO
    NO
    NO
    YES
    YES
    input
    3
    a
    a
    a
    output
    NO
    YES
    YES
    Note

    In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".

    直接枚举啦,就是判断出现过没

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        cin >> n;
        set<string> s;
        for (int i = 0; i < n; i++)
        {
            string c;
            cin >> c;
            if (s.count(c)) puts("YES");
            else puts("NO");
            s.insert(c);
        }
        return 0;
    }
    B. Marvolo Gaunt's Ring
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly x drops of the potion he made.

    Value of x is calculated as maximum of p·ai + q·aj + r·ak for given p, q, r and array a1, a2, ... an such that 1 ≤ i ≤ j ≤ k ≤ n. Help Snape find the value of x. Do note that the value of x may be negative.

    Input

    First line of input contains 4 integers n, p, q, r ( - 109 ≤ p, q, r ≤ 109, 1 ≤ n ≤ 105).

    Next line of input contains n space separated integers a1, a2, ... an ( - 109 ≤ ai ≤ 109).

    Output

    Output a single integer the maximum value of p·ai + q·aj + r·ak that can be obtained provided 1 ≤ i ≤ j ≤ k ≤ n.

    Examples
    input
    5 1 2 3
    1 2 3 4 5
    output
    30
    input
    5 1 2 -3
    -1 -2 -3 -4 -5
    output
    12
    Note

    In the first sample case, we can take i = j = k = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30.

    In second sample case, selecting i = j = 1 and k = 5 gives the answer 12.

    Create a dynamic programming table of size n·3. In this, dp[i][0] stores maximum of value p·ax for x between 1 and i. Similarly dp[i][1] stores the maximum value of p·ax + q·ay such that x ≤ y ≤ i and dp[i][2] stores maximum value of p·ax + q·ay + r·az for x ≤ y ≤ z ≤ i.

    To calculate the dp:

    dp[i][0] = max(dp[i - 1][0], p·ai)

    dp[i][1] = max(dp[i - 1][1], dp[i][0] + q·ai)

    dp[i][2] = max(dp[i - 1][2], dp[i][1] + r·ai)

    The answer will be stored in dp[n][2]

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N=1e5+5;
    ll a[N];
    ll ans[3];
    int main()
    {
        ll n,p,q,r;
        cin>>n>>p>>q>>r;
        for(int i=1; i<=n; i++)
            cin>>a[i];
        for(int i=0; i<3; i++)
            ans[i]=-9e18;
        for(int i=1; i<=n; i++)
        {
            ans[0]=max(ans[0],a[i]*p);
            ans[1]=max(ans[1],ans[0]+q*a[i]);
            ans[2]=max(ans[2],ans[1]+r*a[i]);
        }
        cout<<ans[2]<<endl;
        return 0;
    }
    C. Helga Hufflepuff's Cup
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Harry, Ron and Hermione have figured out that Helga Hufflepuff's cup is a horcrux. Through her encounter with Bellatrix Lestrange, Hermione came to know that the cup is present in Bellatrix's family vault in Gringott's Wizarding Bank.

    The Wizarding bank is in the form of a tree with total n vaults where each vault has some type, denoted by a number between 1 to m. A tree is an undirected connected graph with no cycles.

    The vaults with the highest security are of type k, and all vaults of type k have the highest security.

    There can be at most x vaults of highest security.

    Also, if a vault is of the highest security, its adjacent vaults are guaranteed to not be of the highest security and their type is guaranteed to be less than k.

    Harry wants to consider every possibility so that he can easily find the best path to reach Bellatrix's vault. So, you have to tell him, given the tree structure of Gringotts, the number of possible ways of giving each vault a type such that the above conditions hold.

    Input

    The first line of input contains two space separated integers, n and m — the number of vaults and the number of different vault types possible. (1 ≤ n ≤ 105, 1 ≤ m ≤ 109).

    Each of the next n - 1 lines contain two space separated integers ui and vi (1 ≤ ui, vi ≤ n) representing the i-th edge, which shows there is a path between the two vaults ui and vi. It is guaranteed that the given graph is a tree.

    The last line of input contains two integers k and x (1 ≤ k ≤ m, 1 ≤ x ≤ 10), the type of the highest security vault and the maximum possible number of vaults of highest security.

    Output

    Output a single integer, the number of ways of giving each vault a type following the conditions modulo 109 + 7.

    Examples
    input
    4 2
    1 2
    2 3
    1 4
    1 2
    output
    1
    input
    3 3
    1 2
    1 3
    2 1
    output
    13
    input
    3 1
    1 2
    1 3
    1 1
    output
    0
    Note

    In test case 1, we cannot have any vault of the highest security as its type is 1 implying that its adjacent vaults would have to have a vault type less than 1, which is not allowed. Thus, there is only one possible combination, in which all the vaults have type 2.

     这个题我有点懵

    树形dp,类似于染色吧

    #include <bits/stdc++.h>
    using namespace std;
    const int  N=1e5+5;
    const int MD=1e9+7;
    typedef long long LL;
    int n, m, k, x;
    int f[N][11][3], g[11][3];
    vector < int > V[N];
    void DFS(int u, int fa)
    {
        f[u][0][0] = k - 1;
        f[u][1][1] = 1;
        f[u][0][2] = m - k;
        for(auto &v: V[u])
        {
            if(v == fa) continue;
            DFS(v, u);
            memset(g, 0, sizeof(g));
            for(int i = x; i>=0; --i)
                for(int j=x-i; j>=0; --j)
                {
                    g[i + j][0] = (g[i + j][0] + 1LL * f[u][i][0] * f[v][j][0]) % MD;
                    g[i + j][0] = (g[i + j][0] + 1LL * f[u][i][0] * f[v][j][1]) % MD;
                    g[i + j][0] = (g[i + j][0] + 1LL * f[u][i][0] * f[v][j][2]) % MD;
                    g[i + j][1] = (g[i + j][1] + 1LL * f[u][i][1] * f[v][j][0]) % MD;
                    g[i + j][2] = (g[i + j][2] + 1LL * f[u][i][2] * f[v][j][0]) % MD;
                    g[i + j][2] = (g[i + j][2] + 1LL * f[u][i][2] * f[v][j][2]) % MD;
                }
            for(int i = 0; i <= x; ++i)
                for(int j = 0; j < 3; ++j)
                    f[u][i][j] = g[i][j];
        }
    }
    int main()
    {
        scanf("%d %d", &n, &m);
        for(int i = 1; i < n; ++i)
        {
            int u,v;
            scanf("%d %d", &u, &v);
            V[u].push_back(v);
            V[v].push_back(u);
        }
        scanf("%d %d", &k, &x);
        DFS(1, 0);
        int ans = 0;
        for(int i = 0; i <= x; ++i)
            for(int j = 0; j < 3; ++j)
                ans = (ans + f[1][i][j]) % MD;
        printf("%d
    ", ans);
        return 0;
    }
  • 相关阅读:
    访问H2数据库的SpringBoot工程
    Spring Annotations
    衡量技术/工具好坏的标准
    Maven Waring : GroupId is duplicate of parent groupId 和 Version is duplicate of parent version
    MyEclipse中,使用Maven新建web项目后,提示The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
    Java Web报错:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
    maven项目,代码正确的情况下,整个项目中的类报cannot be resolved to a type 错误
    day46_Webservice学习笔记_02
    CentOS6 PXE+Kickstart无人值守安装
    快速诊断Linux性能
  • 原文地址:https://www.cnblogs.com/BobHuang/p/7591545.html
Copyright © 2011-2022 走看看