BestCoder Round #41 (dp)hdu5229,5230

ZCC loves hacking

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)
Total Submission(s): 61    Accepted Submission(s): 32


Problem Description
Now, a Codefires round is coming to end. ZCC has got C(0C106) points by solving all problems. He is amazed that all other contestants in his room have also solved the hardest problem. So he concludes that most contestants are gonna get FST after the contest except the top rated coder Memset137. Before that, ZCC will hack them to make his score higher. There are N(1N100000) other contestants in ZCC's room. They are sorted by their ratings(So Memset137 is the N-th contestant). When ZCC successfully hacks the i-th contestant, he will get i points. You may assume ZCC can hack every wrong solution in very little time, and Memset137 is the contestant with number N. During that time, other contestants won't bother him.

Since ZCC is a modest winner, he doesn't want his score to be too high. ZCC wonders how many ways are there that he can choose some contestants' solutions except the one submitted by Memset137 and hack them so that his final score is between L and R (CLR<C+N) .

Obviously the result can be very large, so please output it modulo 998244353.
 

Input
The first line contains an integer T(T=100) which denotes the number of test cases.
For each test case, there will be four integers N(N105) , C , L , R in a single line.

For 95% of the test cases, N2000 .
For 97% of the test cases, N50000 .
 

Output
For each test case, print a single integer which is the answer.
 

Sample Input
  
  
3 3 0 1 2 5 13 14 17 100 0 23 59
 

Sample Output
  
  
2 6 90567

题意:ZCC有一个基础分C,hack第i个人得分为i,文有多少种方法可以得分为L,R之间

思路:其实这个C没太有用,直接用L,R减掉就可以,然后就是类似于背包的dp,dp[i][j]表示前i个数和为j的有多少个,因为C<=L,R<=C+N,所以最多加到400左右,复杂度就够了

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
const int maxn=100010;
const int maxm=450;
const int MOD=998244353;
int N,C,L,R,cur;
long long dp[maxn],p[maxn],q[maxn];
void init()
{
    p[0]=1;
    //cur=1;
    for(int i=1;i<maxm;i++)
    {
        for(int j=0;j<maxn;j++)
            dp[j]=(dp[j]+p[j])%MOD;
        for(int j=0;j<i;j++)q[j]=0;
        for(int j=i;j<maxn;j++)
            q[j]=(q[j-i]+p[j-i])%MOD;
        swap(q,p);
    }
    for(int i=1;i<maxn;i++)
        dp[i]=(dp[i]+dp[i-1])%MOD;
}
int main()
{
    init();
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d%d",&N,&C,&L,&R);
        cout<<(dp[R-C]-dp[L-C-1]+MOD)%MOD<<endl;
    }
}

ZCC loves strings

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)
Total Submission(s): 234    Accepted Submission(s): 88


Problem Description
ZCC has got N strings. He is now playing a game with Miss G.. ZCC will pick up two strings among those N strings randomly(A string can't be chosen twice). Each string has the same probability to be chosen. Then ZCC and Miss G. play in turns. Miss G. always plays first. In each turn, the player can choose operation A or B.
  
Operation A: choose a non-empty string between two strings, and delete a single letter at the end of the string.
    
Operation B: When two strings are the same and not empty, empty both two strings.
  
The player who can't choose a valid operation loses the game.
  
ZCC wants to know what the probability of losing the game(i.e. Miss G. wins the game) is.
 

Input
The first line contains an integer T(T5) which denotes the number of test cases.
  
For each test case, there is an integer N(2N20000) in the first line. In the next N lines, there is a single string which only contains lowercase letters. It's guaranteed that the total length of strings will not exceed 200000.
 

Output
For each test case, output an irreducible fraction "p/q" which is the answer. If the answer equals to 1, output "1/1" while output "0/1" when the answer is 0.
 

Sample Input
  
  
1 3 xllendone xllendthree xllendfour
 

Sample Output
  
  
2/3

思路:只有当两个串的长度和为奇数或者长度相等的时候,ZCC才会输

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=200010;
typedef long long LL;
int N;
int vis[maxn];
string a[maxn];
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        cin>>N;
        int cnt=0,even=0;
        memset(vis,0,sizeof(vis));
        for(int i=0;i<N;i++)
        {
            cin>>a[i];
            if(a[i].size()%2)cnt++;
            else even++;
            vis[a[i].size()]++;
        }
        LL up=(LL)cnt*even;
        sort(a,a+N);
        int k=0;
        for(int i=1;i<N;i++)
        {
            if(a[i]==a[i-1])
            {
                k++;
                up+=k;
            }
            else k=0;
        }
        LL down=((LL)N*(N-1))/2;
        LL g=__gcd(up,down);
        cout<<up/g<<"/"<<down/g<<endl;
    }
    return 0;
}





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值