BestCoder Round #35(DZY Loves Balls-暴力dp)
来源:互联网 发布:机顶盒直播软件下载 编辑:程序博客网 时间:2024/05/01 04:14
DZY Loves Balls
Accepts: 371
Submissions: 988
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
这次学乖,开始DP乱搞
其实还有更简单的敲公式法,,不过我就直接把打表程序交了
next_permunation 这种暴力也是可以的??
#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<functional>#include<iostream>#include<cmath>#include<cctype>#include<ctime>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)#define MAXN (100) typedef long long ll;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return (a-b+(a-b)/F*F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}ll gcd(ll a,ll b){if (b==0) return a;return gcd(b,a%b);}class fenshu{public:ll a,b; //分母a 分子b fenshu(ll _b,ll _a):a(_a),b(_b){}fenshu():a(1),b(0){}void relax(){int t=gcd(a,b);a/=t,b/=t;}friend fenshu operator*(fenshu a,fenshu b){fenshu c=fenshu(a.b*b.b,a.a*b.a);c.relax();return c;}friend fenshu operator+(fenshu a,fenshu b){fenshu c=fenshu(a.a*b.b+a.b*b.a,a.a*b.a);c.relax();return c;}void pri(){cout<<b<<'/'<<a;}}f[MAXN][MAXN][2];int n,m;void turn_out(int n,int m){fenshu t=f[n][m][0]*fenshu(m,n)+f[n][m][1]*fenshu(n-m,n); t.pri();} int main(){//freopen("a.in","r",stdin);n=24,m=12;Fork(i,2,n)Rep(j,i+1){int k=0;f[i][j][k]=f[i-1][j-1][0]*fenshu(j-1,i-1)+f[i-1][j-1][1]*fenshu(i-j,i-1);k=1;f[i][j][k]=(fenshu(1,1)+f[i-1][j][0])*fenshu(j,i-1)+f[i-1][j][1]*fenshu(i-1-j,i-1);}/*For(i,24){Rep(j,min(i+1,13)){turn_out(i,j);cout<<' ';}cout<<endl;}*/while(scanf("%d%d",&n,&m)==2){n+=m;fenshu t=f[n][m][0]*fenshu(m,n)+f[n][m][1]*fenshu(n-m,n); t.pri();cout<<endl;}return 0;}
0 0
- BestCoder Round #35(DZY Loves Balls-暴力dp)
- HDU-5194-DZY Loves Balls(BestCoder Round # 35 )
- BestCoder Round #76 (div.2) DZY Loves Balls
- BestCoder Round #35(DZY Loves Topological Sorting-堆+贪心)
- hdu 5195 DZY Loves Topological Sorting && BestCoder Round #35
- hdu 5196 DZY Loves Inversions && BestCoder Round #35
- hdu 5194 DZY Loves Balls (dp)
- hdu 5194 DZY Loves Balls(暴力,数学期望)
- hdu DZY Loves Balls
- DZY Loves Balls
- DZY Loves Balls
- BestCoder Round #76 (div.2)-DZY Loves Partition(模拟)
- 【BestCoder Round #76 (div.2)】DZY Loves Partition(数学分析)
- 【BestCoder Round #76 (div.2)】HDU5646DZY Loves Balls
- 【HDU5647 BestCoder Round 76 (div1)B】【树形DP】DZY Loves Connecting 一棵树的所有生成子树的大小乘积
- HDU 5194 DZY Loves Balls
- HDU5194 DZY Loves Balls【排列组合】
- HDU 5194 DZY Loves Balls
- myeclipse启动tomcat会出现 a java exception has occured错误 的解决方法
- 将两个字符串连接起来 用string
- 这是一道面试试题,求大神解答
- SQL性能优化
- SQL 与 sqlite
- BestCoder Round #35(DZY Loves Balls-暴力dp)
- udp打洞
- LeetCode Longest Valid Parentheses
- 题目1075:斐波那契数列
- nodejs的require模块及路径
- P51第12题
- Class.forName和newInstance两个方法
- HDU 4035 Maze 概率dp
- Android Fragment