题目链接:

KK's Point

Time Limit: 2000/1000 MS (Java/Others)   

 Memory Limit: 65536/65536 K (Java/Others)

Problem Description
 
Our lovely KK has a difficult mathematical problem:He points N(2≤N≤10^5) points on a circle,there are all different.Now he's going to connect the N points with each other(There are no three lines in the circle to hand over a point.).KK wants to know how many points are there in the picture(Including the dots of boundary).
 
Input
 
The first line of the input file contains an integer T(1≤T≤10), which indicates the number of test cases.

For each test case, there are one lines,includes a integer N(2≤N≤10^5),indicating the number of dots of the polygon.

 
Output
 
For each test case, there are one lines,includes a integer,indicating the number of the dots.
 
Sample Input
2
3
4
 
Sample Output
3
5
 
题意:
 
在圆上有n个点,每两个点都相连,问连线有多少个交点,任意三根线不交于同一点;
 
思路
 
dp来解决,每加入一个点我们可以发现,增加的交点个数为1*n+2*(n-1)+3*(n-2)+...+n*1+1(最后这个1是这个点本身);
这是怎么来的可以画个图来自己画一下看看;每次把原先的点分成两拨;
 
现在的问题变成怎么求上述的式子了;
 
f(n)=1*n+2*(n-1)+3*(n-2)+...+n*1;
f(n+1)=1*(n+1)+2*n+3*(n-1)+...+(n+1)*1;
f(n+1)-f(n)=(n+1)+n+(n-1)+(n-2)+...+1=(n+1)(n+2)/2;
那么状态转移方程就有了dp[i]=dp[i-1]+1+f(i-3);
 
 
AC代码
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long ll;
const ll mod=1e9+;
const ll inf=1e15;
const int N=1e5+;
int n;
ll dp[N],f[N];
void fun()
{
dp[]=;//注意dp[1] dp[2]的初始化,我在这里就wa了一发;
dp[]=;
dp[]=;
f[]=;
for(int i=;i<N;i++)
{
ll x=(i);
f[i]=f[i-]+x*(x+)/;
}
for(int i=;i<N;i++)
{
dp[i]=dp[i-]++f[i-];
}
}
int main()
{
int t;
scanf("%d",&t);
fun();
while(t--)
{
scanf("%d",&n);
cout<<dp[n]<<"\n";
//printf("%lld\n",dp[n]);
}
return ;
}

hdu-5621 KK's Point(dp+数学)的更多相关文章

  1. hdu 5621 KK's Point(数学,推理题)

    题解: 在圆上点三个点时,除圆上三个交点外,圆内没有交点:在圆上点四个点时,除圆上四个交点外,圆内出现了一个交点,因此,在N个点中每四个点便可以在圆内产生一个交点,因此N个点在圆内形成的点的个数为CN ...

  2. HDU 5628 Clarke and math dp+数学

    Clarke and math 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5628 Description Clarke is a patient ...

  3. HDU 5622 KK's Chemical DP

    题意:bc round 71(中文题面) 分析(官方题解): 根据药品之间的相互关系,我们可以构建一张图,我们对相互会发生反应的药品连边 这个图的特征,是一个环加上一些“树”(可能有多个联通块) 一个 ...

  4. HDU 5621 KK's Point

    N个点中任意选取四个点,就能产生一个圆内的交点,所以圆内总共有C(N,4)个交点,圆上有N个,相加就可以了. 注意:组合数运算的时候会爆longlong,中间先除一下就可以了. #include &l ...

  5. HDU 1003 Max Sum --- 经典DP

    HDU 1003    相关链接   HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...

  6. hdu 5094 Maze 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...

  7. hdu 2829 Lawrence(斜率优化DP)

    题目链接:hdu 2829 Lawrence 题意: 在一条直线型的铁路上,每个站点有各自的权重num[i],每一段铁路(边)的权重(题目上说是战略价值什么的好像)是能经过这条边的所有站点的乘积之和. ...

  8. hdu 4568 Hunter 最短路+dp

    Hunter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  9. HDU 1231.最大连续子序列-dp+位置标记

    最大连续子序列 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

随机推荐

  1. go 协程与主线程强占运行

    最近在学习了Go 语言 ,  正好学习到了 协程这一块 ,遇到了困惑的地方.这个是go语言官方文档 . 在我的理解当中是,协程只能在主线程释放时间片后才会经过系统调度来运行协程,其实正确的也确实是这样 ...

  2. Hadoop 2.2.0集群搭建

    一.环境说明 1.虚拟机平台:VMware10 2.Linux版本号:ubuntu-12.04.3-desktop-i386 3.JDK:jdk1.7.0_51 4.Hadoop版本号:2.2.0 5 ...

  3. WinKawaks使用技巧

    1 关于载入游戏:把游戏的zip文件放到roms目录下.注意不要随意修改文件名!也不要让文件名有中文!例如:"[游戏roms][neogeo]mslugx.zip"改成" ...

  4. sparkSQL1.1入门之十:总结

    回想一下,在前面几章中,就sparkSQL1.1.0基本概念.执行架构.基本操作和有用工具做了基本介绍. 基本概念: SchemaRDD Rule Tree LogicPlan Parser Anal ...

  5. [LeetCode][Java] Combinations

    题目: Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For ex ...

  6. C#自定义类型数组排序

    在数组或者集合中对自定义类型进行排序分为两种方法. 1.如果这个自定义类型是自己定义编写的,那么我可以使它继承ICompareable<T>接口,实现其中的CompareTo(Object ...

  7. uboot 命令

    1.清除前一次的编译结果: make distclean 2.配置makefile:选择开发板 make  smdk6410_config 3.编译 make 注意::编译时,打开的文档文件,目录都要 ...

  8. Integrate NSX into Neutron

    NSX is VMware's strategy for Software-defined networking, it was implemented purely in software, and ...

  9. 关于angular JS 中$timeOut 的一些不正常情况下的$destory

    最近项目中存在的问题头疼脑热了好一会. 我先简单说明下问题是由,使用$timeOut循环调用的时候由于页面存在异步加载会出现反复执行循环反复调用$timeOut,怎么清除跳出循环都不管用.于是查到了如 ...

  10. HDU 3308 LCIS (线段树&#183;单点更新&#183;区间合并)

    题意  给你一个数组  有更新值和查询两种操作  对于每次查询  输出相应区间的最长连续递增子序列的长度 基础的线段树区间合并  线段树维护三个值  相应区间的LCIS长度(lcis)  相应区间以左 ...