hdu 5185 Equation(dp题)
2017-08-09 10:31
417 查看
Equation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 647 Accepted Submission(s): 227
Problem Description
Gorwin is very interested in equations. Nowadays she gets an equation like this
x1+x2+x3+⋯+xn=n, and here
0≤xi≤nfor1≤i≤nxi≤xi+1≤xi+1for1≤i≤n−1
For a certain n, Gorwin wants to know how many combinations of xi satisfies above condition.
For the answer may be very large, you are expected output the result after it modular m.
Input
Multi test cases. The first line of the file is an integer T indicates the number of test cases.
In the next T lines, every line contain two integer n,m.
[Technical Specification]
1≤T<20
1≤n≤50000
1≤m≤1000000000
Output
For each case output should occupies one line, the output format is Case #id: ans, here id is the data number starting from 1, ans is the result you are expected to output.
See the samples for more details.
Sample Input
2
3 100
5 100
Sample Output
Case #1: 2
Case #2: 3
Source
BestCoder Round #32
Recommend
hujie
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 647 Accepted Submission(s): 227
Problem Description
Gorwin is very interested in equations. Nowadays she gets an equation like this
x1+x2+x3+⋯+xn=n, and here
0≤xi≤nfor1≤i≤nxi≤xi+1≤xi+1for1≤i≤n−1
For a certain n, Gorwin wants to know how many combinations of xi satisfies above condition.
For the answer may be very large, you are expected output the result after it modular m.
Input
Multi test cases. The first line of the file is an integer T indicates the number of test cases.
In the next T lines, every line contain two integer n,m.
[Technical Specification]
1≤T<20
1≤n≤50000
1≤m≤1000000000
Output
For each case output should occupies one line, the output format is Case #id: ans, here id is the data number starting from 1, ans is the result you are expected to output.
See the samples for more details.
Sample Input
2
3 100
5 100
Sample Output
Case #1: 2
Case #2: 3
Source
BestCoder Round #32
Recommend
hujie
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; #define N 50010 int dp[500] ; int main() { int T,t=1; long long n,m; scanf("%d",&T); while(T--) { scanf("%lld %lld",&n,&m); int k=1; while(k*(k+1)<=2*n) k++; k--; for(int i=0;i<=n;i++) dp[0][i]=0; for(int i=1;i<=k;i++) dp[i][0]=0; dp[0][0]=1; for(int i=1;i<=k;i++) { for(int j=i;j<=n;j++) { dp[i][j]=(dp[i][j-i]+dp[i-1][j-i])%m; } } long long ans=0; for(int i=1;i<=k;i++) ans=(ans+dp[i] )%m; printf("Case #%d: %lld\n",t++,ans); } return 0; }
相关文章推荐
- hdu 5185 Equation(DP,思路)
- HDU 5185 Equation (DP)
- HDU 5185 Equation (线性dp 完全背包)
- HDU 5185 Equation (DP)
- hdu 5185 Equation(分析+DP)
- hdu 5185 dp
- HDU:4249 A Famous Equation(数位DP)
- hdu 5185(DP)
- hdu 5185(dp)
- hdu 5185 Equation (完全背包变形)
- HDU 4294 A Famous Equation(DP)
- hdu 5185 Equation && BestCoder Round #32
- HDU 4249 A Famous Equation(数位DP)
- HDU 4249 A Famous Equation(数位DP)
- hdoj 5185 Equation (线性dp 完全背包)
- HDU-4249-A Famous Equation(DP)
- 【DP】 HDOJ 5185 Equation
- hdu 5185 dp(完全背包)
- hdu 5185 dp(完全背包)+优化
- hdu 4249 A Famous Equation【DP】【Fudan Local Programming Contest 2012 E】