题目链接:

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. 在DevExpress GridControl中添加进度条控件 z

    首先可以使用 DevExpress GridControl 自带的进度条控件. 但是我要用一个方法来设置所有的单元格进度,而不是每个单元格都要设置一遍,同时我想要根据进度值不同,进度条显示不同的颜色. ...

  2. Java中字符串转为16进制表示

    Java中字符串转为16进制表示 String str = "鲸"; char[] chars = "0123456789ABCDEF".toCharArray ...

  3. MIDI制作的相关软件

    Native Instruments Kontakt(音乐采样器) fl studio 12 v12.5.0.59 汉化版水果   http://xiazai.flstudiochina.com/wm ...

  4. ffmpeg h264编码 extradata 为空

    ffmpeg h264编码的例子前面的文章已经介绍,本来主要讲述影响AVCodecContext extradata是否为 空的配置项.如果要求open编码器以后AVCodecContext extr ...

  5. 【转载】C#扫盲之:带你掌握C#的扩展方法、以及探讨扩展方法的本质、注意事项

    1.为什么需要扩展方法 .NET3.5给我们提供了扩展方法的概念,它的功能是在不修改要添加类型的原有结构时,允许你为类或结构添加新方法. 思考:那么究竟为什么需要扩展方法呢,为什么不直接修改原有类型呢 ...

  6. Python+Selenium框架 ---自动化测试报告的生成

    本文来介绍如何生成自动化测试报告,前面文章尾部提到了利用HTMLTestRunner.py来生成自动化测试报告.关于HTMLTestRunner不过多介绍,只需要知道是一个能生成一个HTML格式的网页 ...

  7. Mysql启动自己主动设置max_connections为其它值

    背景 有同学反应.产品连不上,登陆到server.发现连接数不够了. 接着先重新启动mysql,发如今mysql启动的时候会报Waring Warning Changed limits: max_op ...

  8. 系统安全-PAM

    Pluggable Authentication Modules(可插入验证模块,简称PAM) Linux-PAM(Pluggable Authentication Modules for Linux ...

  9. JS 省市两级联动(不带地区版本)

    基于网上找的一个版本改造,因为项目需求不需要地区只要省.市,所以做了改版,两个input上直接取出了数据 <html> <head> <script src=" ...

  10. Ionic + AngularJS angular-translate 国际化本地化解决方案

    欢迎访问我们的网站,网站上有更多关于技术性的交流:http://www.ncloud.hk/技术分享/ionic-plus-angularjs-angular-translate-国际化本地化解决方案 ...