摘要: 【题目描述】有n堆石子排成一列,每堆石子有一个重量w[i], 每次合并可以合并相邻的两堆石子,一次合并的代价为两堆石子的重量和w[i]+w[i+1]。问安排怎样的合并顺序,能够使得总合并代价达到最小。 【输入描述】第一行一个整数n(n<=100)。 第二行n个整数w1,w2...wn(wi <= 1 阅读全文
posted @ 2016-03-20 11:05 【機關】 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 源代码: #include<cstdio> int m,n,ans(0),i1[3001],i2[3001],f[3001][3001]={0}; //二维。 int main() { scanf("%d",&m); scanf("%d",&n); for (int a=1;a<=m;a++) sc 阅读全文
posted @ 2016-03-12 21:25 【機關】 阅读(866) 评论(0) 推荐(0) 编辑
摘要: 一、全排列 源代码: #include<cstdio> #include<algorithm> //包含【next_permutation】。 using namespace std; int n,i[1001]; int main() { scanf("%d",&n); //输出1~n的全排列。 阅读全文
posted @ 2016-03-11 20:43 【機關】 阅读(160) 评论(0) 推荐(0) 编辑
摘要: #include<cstdio> int n; void x1_and() { if (n&1) printf("奇数\n"); else printf("偶数\n"); } void x2_or() { printf("%d\n",n|1); //+1奇数 。 printf("%d\n",(n|1 阅读全文
posted @ 2016-02-26 21:58 【機關】 阅读(285) 评论(0) 推荐(0) 编辑
摘要: 这个寒假去了河南,见到了许多大犇,我也渴望像他们一样静静地装逼。培训完了感觉,额,其实在这个世界上有很多装逼的方式······ 前两天听了北大的李煜东神犇的课,讲的真TM的好,“这个XXX大家都会吧。”“会个J8!”、“这个XXX其实很水的。”“你若做一只王八。”······WTF!朱全民老先生讲得 阅读全文
posted @ 2016-02-26 20:40 【機關】 阅读(1968) 评论(0) 推荐(0) 编辑
摘要: 源代码: #include<iostream> using namespace std; string s; int n,num(0); struct treetype { char t; //用于节点储存字符。 bool over; //用于标记是否为此字符串的终结。 int next,deep, 阅读全文
posted @ 2016-02-16 18:46 【機關】 阅读(576) 评论(0) 推荐(0) 编辑
摘要: 源代码: #include<cstdio> #include<iostream> using namespace std; string s1,s2; int m,n,k(0),next[1001]; //在Next数组中,存储的是匹配失败后,上一位应该跳跃到的节点编号。 int main() { 阅读全文
posted @ 2016-02-15 21:44 【機關】 阅读(289) 评论(0) 推荐(0) 编辑
摘要: 源代码: #include<cstdio> int n; void x1(int x,int y) { x-=2; //利用规律:[F(n),F(n-1)]=[F(n-1),F(n-2)]*[1,1/1,0]。 int t1=1,t2=0,t3=0,t4=1; //在矩阵乘法中,[1,1/1,1]的 阅读全文
posted @ 2016-02-15 12:11 【機關】 阅读(398) 评论(0) 推荐(0) 编辑
摘要: 源代码: #include<cstdio> int n,num(0),h[100001]; struct treetype { int left,right,lefts,rights,sum,sign; }i[200020]; void x1(int t1,int t2) //建树。 { int t 阅读全文
posted @ 2016-02-14 14:56 【機關】 阅读(234) 评论(0) 推荐(0) 编辑
摘要: 源代码: #include<cstdio> int m,n,num(0),h[100001]; struct treetype { int left,right,lefts,rights,sum; //本代码中,应用为半开半闭区间。 }i[200020]; //应用了完全二叉树的结点个数公式。 vo 阅读全文
posted @ 2016-02-13 20:08 【機關】 阅读(625) 评论(0) 推荐(1) 编辑