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(0≤C≤106) 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(1≤N≤100000) 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 (C≤L≤R<C+N) .
Obviously the result can be very large, so please output it modulo 998244353.
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
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 integersN(N≤105) ,C ,L ,R in a single line.
For 95% of the test cases,N≤2000 .
For 97% of the test cases,N≤50000 .
For each test case, there will be four integers
For 95% of the test cases,
For 97% of the test cases,
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.
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(T≤5) which denotes the number of test cases.
For each test case, there is an integerN(2≤N≤20000) 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.
For each test case, there is an integer
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
- BestCoder Round #41 (dp)hdu5229,5230
- BestCoder Round #75 1003 数位DP
- hdu5904 BestCoder Round #87 LCIS -dp
- BestCoder Round #92【map,枚举,DP】
- BestCoder Round #75 King's Order dp:数位dp
- hdu 5230 ZCC loves hacking(BestCoder Round #41)
- hdu 5230 ZCC loves hacking && BestCoder Round #41 1003
- HDU 4907 - Task schedule(BestCoder Round #3 简单DP)
- BestCoder Round #13 1003(单调性DP)HDU5064
- BestCoder Round #35(DZY Loves Balls-暴力dp)
- HDU 5280 BestCoder Round#47 1001 ---枚举+dp
- BestCoder Round #50 (div.2) & HDOJ5366 The mook jong(dp)
- BestCoder Round #63 (div.2) HDOJ5568 sequence2(dp + 大数)
- BestCoder Round #63 (div.2) HDOJ5569 matrix(dp)
- BestCoder Round #65 D. ZYB's Tree(树形dp)
- BestCoder Round #68 (div.1) B 矩阵乘法优化DP
- BestCoder Round #70 1002 Jam's balance(DP)
- hdu 5617 Jam's maze(dp)(BestCoder Round #70)
- 机器学习实战——第四章:朴素贝叶斯
- MFC学习(17)数据库对于给定起始时间和目标统计时间段的情况如何处理
- 阅3、4
- 深入源码剖析LruCache
- windows程序设计——消息循环
- BestCoder Round #41 (dp)hdu5229,5230
- 20个可能成为设计师的习惯
- 天声人語 20150517
- Http 和TCP的关系,TCP长连接和短连接有什么区别?
- c++返回字符串
- MFC学习(16)对于ACCESS数据库的时间查询
- 点击导航栏列表自动返回第一个cell,及顶部
- .NET版三层登录
- linux常用命令