2017多校-8

来源:互联网 发布:人工智能的龙头股 编辑:程序博客网 时间:2024/06/05 03:41

Hybrid Crystals
http://acm.hdu.edu.cn/showproblem.php?pid=6140

贴一个别人的题解
我们考虑到,n的范围达到了1e3,如果要从这n个数中选择一些数直接凑的话,近乎不可能完成。
题目中又写到,为降低题目难度,增加了两个约束条件:
①.a_1一定是1,它的下标一定是N。
②.【重点】给出后n-1个数的范围:a_i ≤ (j从1——i-1的)(所有下标为N的a_j之和)+ (a_i下标为L ? a_j下标为L的数值)+ (a_i下标为D ? a_j下标为D的数值)。然而这个条件有什么用呢?
它间接表明第一个下标为L的数,只能取0或1;
(在不出现N时)第二个下标为L的数只能是0或1或2;
(在不出现N时)第三个下标为L的数取值范围为0-4;
(在不出现N时)第四个下标为L的数取值范围为0-8;
……
而这范围有什么用呢?
它保证了新增加下标为L的数时,整个序列可表示的数的范围的上界随之扩大,即可以用所给的数表示0-上界中的任意一个数。
(如在不出现N时前四个下标为L的a_i分别是1,2,4,8,则我可以从这些数中选出0-4个数来表示0-15中的任意一个数)
同理,把上面的L换为D,可得到整个序列能表示的数的范围的下界。
因此,在碰到下标为L的数就更新序列所能表示的数的范围的上界,碰到下标为D时就更新下界。因为下标为N的数可正可负,所以当出现N时,更新L边界的过程中就把N看作L,更新D边界过程中就把N看作D(即同时更新上下界)。
最后看k是否在能表示的范围内就可以了。

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;int main(){    int t;    scanf("%d",&t);    while(t--)    {        int n,k;        scanf("%d%d",&n,&k);        int a[1010];        for(int i=1;i<=n;i++)        {            scanf("%d",&a[i]);        }        getchar();        char ch;        int sum1=0,sum2=0;        for(int i=1;i<=n;i++)        {            scanf("%c",&ch);            if(ch=='N')            {                sum1+=a[i];                sum2-=a[i];            }            else if(ch=='L')            {                sum1+=a[i];            }            else if(ch=='D')            {                sum2-=a[i];            }            getchar();        }        if(sum1>=k&&sum2<=k)        {            printf("yes\n");        }        else        {            printf("no\n");        }    }    return 0;}

Killer Names
http://acm.hdu.edu.cn/showproblem.php?pid=6143

N个球放M个盒子问题:https://bbs.qzzn.com/thread-14856448-1-1.html

标程

#include <assert.h>#include <string.h>#include <stdlib.h>#include <stdio.h>#include <algorithm>#include <iostream>#include <map>#include <queue>#include <string>#include <vector>using namespace std;#define debug printf("%s %d\n", __FUNCTION__, __LINE__)const int mod = 1e9 + 7;const int maxn = 2000 + 10;int power(int x, int times) {    int rt = 1;    int base = x;    while (times) {        if (times & 1) rt = 1LL * rt * base % mod;        base = 1LL * base * base % mod;        times >>= 1;    }    return rt;}int dp[maxn][maxn];void calc_dp(int n, int m) {    dp[1][1] = m;    for (int i = 2; i <= n; i++) {        for (int j = 1; j <= min(m, i); j++) {            dp[i][j] = (1LL * dp[i - 1][j] * j + 1LL * dp[i - 1][j - 1] * (m - j + 1)) % mod;        }    }}int c[maxn][maxn];int f[maxn];int main(int argc, char **argv) {    for (int i = 0; i < maxn; i++) {        c[i][0] = c[i][i] = 1;        for (int j = 1; j < i; j++)             c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;    }    int cases;    int n, m;    scanf("%d", &cases);    while (cases--) {        scanf("%d%d", &n, &m);        assert(1 <= n && n <= 2000);        assert(1 <= n && n <= 2000);        int ans = 0;        for (int i = 1; i < m; i++) {            if (i > n) break;            f[i] = power(i, n);            for (int j = 1; j < i; j++) {                f[i] = (f[i] - 1LL * c[i][j] * f[j]) % mod;            }            ans = (ans + 1LL * f[i] * c[m][i] % mod * power(m - i, n)) % mod;        }        calc_dp(n, m);        int dp_ans = 0;        for (int i = 1; i < m; i++) {            int c = dp[n][i];            for (int j = 0; j < n; j++)                 c = 1LL * c * (m - i) % mod;            dp_ans = (dp_ans + c) % mod;        }        ans = (ans + mod) % mod;        printf("%d\n", ans);    }    return 0;}
原创粉丝点击