HDU1396:Counting Triangles -DP

来源:互联网 发布:淘宝便宜的手办店 编辑:程序博客网 时间:2024/05/03 18:37
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1396//根据每增加一条边所增加的正三角和倒三角的个数构造方程 #include<cstdio>#include<cstring>__int64 dp[510];int main(){int n;memset(dp,0,sizeof(dp));    dp[1]=1;for(int i=2;i<=500;i++){if(i&2==1){dp[i]=dp[i-1]+(i*i-1)/4+i*(i+1)/2;}else{dp[i]=dp[i-1]+(i*i)/4+i*(i+1)/2;}}while(~scanf("%d",&n)){printf("%I64d\n",dp[n]);}return 0; } 

0 0
原创粉丝点击