BestCoder Round #41 (dp)hdu5229,5230

来源:互联网 发布:linux安卓 编辑:程序博客网 时间:2024/05/21 08:53

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 betweenL 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
33 0 1 25 13 14 17100 0 23 59
 

Sample Output
2690567

题意: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
13xllendonexllendthreexllendfour
 

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 0
原创粉丝点击