ZOJ 3647 Gao the Grid
来源:互联网 发布:听歌学英语的软件 编辑:程序博客网 时间:2024/05/02 00:11
dp一下吧~简单的组合数学题
#include<iostream>#include<vector>#include<algorithm>#include<cstdio>#include<queue>#include<stack>#include<string>#include<map>#include<set>#include<cmath>#include<cassert>#include<cstring>#include<iomanip>using namespace std;#ifdef _WIN32#define i64 __int64#define out64 "%I64d\n"#define in64 "%I64d"#else#define i64 long long#define out64 "%lld\n"#define in64 "%lld"#endif/************ for topcoder by zz1215 *******************/#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)#define FFF(i,a) for( int i = 0 ; i < (a) ; i ++)#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)#define S64(a) scanf(in64,&a)#define SS(a) scanf("%d",&a)#define LL(a) ((a)<<1)#define RR(a) (((a)<<1)+1)#define pb push_back#define CL(Q) while(!Q.empty())Q.pop()#define MM(name,what) memset(name,what,sizeof(name))#define MC(a,b)memcpy(a,b,sizeof(b))#define MAX(a,b) ((a)>(b)?(a):(b))#define MIN(a,b) ((a)<(b)?(a):(b))#define read freopen("in.txt","r",stdin)#define write freopen("out.txt","w",stdout)const int inf = 0x3f3f3f3f;const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;const double oo = 10e9;const double eps = 10e-9;const double pi = acos(-1.0);const int maxn = 1001;int n,m;i64 dp[maxn][maxn];i64 s[maxn][maxn];int gcd(int _a, int _b){ if (!_a || !_b) { return max(_a, _b); } int _t; while ((_t = _a % _b)) { _a = _b; _b = _t; } return _b;}void init(){dp[0][0]=0;s[0][0]=0;for(int i=1;i<maxn;i++){dp[0][i]=0;s[0][i]=0;dp[i][0]=0;s[i][0]=0;}int temp;for(int i=1;i<maxn;i++){for(int j=1;j<maxn;j++){temp = gcd(i,j);dp[i][j]=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]+temp-1;}}for(int i=1;i<maxn;i++){for(int j=1;j<maxn;j++){s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+dp[i][j];}}return ;}i64 find(){i64 re=0;i64 temp;temp = n+1;temp*= m+1;temp = temp*(temp-1)*(temp-2);temp/= 6;re = temp;re -= s[n][m];re -= s[m][n];temp = n+1;temp = temp*(temp-1)*(temp-2);temp/=6;temp*= m+1;re -= temp;temp = m+1;temp = temp*(temp-1)*(temp-2);temp /=6;temp*=n+1;re -= temp;return re;}int main(){init();while(cin>>n>>m){cout<<find()<<endl;}return 0;}
- ZOJ 3647 Gao the Grid
- ZOJ 3647 Gao the Grid
- zoj 3647 Gao the Grid
- ZOJ-3647 Gao the Grid
- ZOJ 3647 Gao the Grid
- Zoj 3647 Gao the Grid (数论?)
- ZOJ 3647 Gao the Grid(居然是暴力)
- ZOJ 3647 Gao the Grid (计数 + pick定理)
- ZOJ 3648 Gao the Grid II
- Zoj 3647 Gao the Grid ( 2012年浙大9月月赛)组合数学
- zoj 3647 Gao the Grid(矩阵对角线三点共线)
- zoj 3647 Gao the Grid (求三角形的个数,困难)
- zoj 3672 Gao The Sequence
- zoj - 3672 - Gao The Sequence
- ZOJ 3672 Gao The Sequence
- Gao the Grid zoj3647(数论)
- ZOJ 3535 Gao the String II
- zoj3647 Gao the Grid----方格中的三点共线
- java 设计模式学习笔记三 Builder模式
- java中的垃圾回收
- 【数据中国大讲坛@国庆献礼】20120930讲座合集
- 当今程序员必须掌握的十种关键技术排名
- 建设一个靠谱的火车票网上订购系统
- ZOJ 3647 Gao the Grid
- 阿里巴巴笔试题目(2009.9)
- 在iOS开发中使用FMDB
- 阿里巴巴面经
- JAVA经典的50道题
- HDOJ 2159 FATE (二维完全背包)
- 我的五面经历--腾讯 百度 支付宝 阿里巴巴
- linux_数学函数的使用___操作
- [Shell]: Linux命令find命令用法总结