Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a ...
分类:
其他好文 时间:
2014-07-08 21:44:23
阅读次数:
177
线段树应用:
有一个数列,初始时为 a1,a2,… aN (N
1) 将 ai 的值加上 val ;
2) 对于一个区间[l,r],该区间的和。
3) 对于一个区间[l,r],求该区间的最大值。
数据结构:
//Node Type
struct Node{
int left, right;
int max, sum;
} tree[maxn];
/*
tree[k]'...
分类:
其他好文 时间:
2014-07-08 21:31:33
阅读次数:
237
Max Sum
Time Limit: 2000ms Memory limit: 32768K 有疑问?点这里^_^
题目描述
Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-...
分类:
其他好文 时间:
2014-07-08 21:30:17
阅读次数:
205
Description
Imagine you are standing inside a two-dimensional maze composed of square cells which may or may not be filled with rock. You can move north, south, east or west one cell at a step. T...
分类:
其他好文 时间:
2014-07-08 21:04:29
阅读次数:
347
这题目的思路很巧妙,什么情况下剩下的所有物品都放不下呢?就是当前剩余物品中最小的那个也放不下。所以,先把物品按照容量从小到大排序,依次枚举当前背包为放不下的最小物品的情况。
对于当前物品i,必有1到i-1的所有物品都放进去,这时候比i大的物品谁放谁不放是不确定的。转换成0-1背包问题:把前i-1个物品都放进去以后,得到空间为tsum - sum[i-1](前缀和)的包,只要从第i+1到第n个物品...
分类:
其他好文 时间:
2014-07-08 19:47:17
阅读次数:
187
题目大意:
求出斐波那契中的 第 k*i+b 项的和。
思路分析:
定义斐波那契数列的矩阵
f(n)为斐波那契第n项
F(n) = f(n+1)
f(n)
那么可以知道矩阵
A = 1 1
1 0
使得 F(n) = A * F(n+1)
然后我们化简最后的答案
sum = F(b) + F(K+b) + F (2*k +...
分类:
其他好文 时间:
2014-07-08 14:47:19
阅读次数:
162
前几天在做结账的时候,对数据表DataGridView控件的单列求和纠结了一番。
现在几乎养成了习惯,对于一些东西疏于开始的思考,不会先想到百度,这里我是先想到了第一版的机房收费那块的结账求和:
截取了充值金额片段,代码如下:
'读取充值金额
strSQL = "select sum(addmoney) as AddCash from Re...
分类:
其他好文 时间:
2014-07-08 14:31:33
阅读次数:
160
You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s ...
分类:
其他好文 时间:
2014-07-08 13:34:40
阅读次数:
195
Flip Game
Time Limit: 1000MS
Memory Limit: 65536K
Total Submissions: 29713
Accepted: 12876
Description
Flip game is played on a rectangular 4x4 field with two-sided...
分类:
其他好文 时间:
2014-07-08 13:32:49
阅读次数:
189
题意:N个点(0~n-1),M条无向边,问去掉2个点后最多的连通分块有多少。
先去掉一个点求出各个割点,并在dfs过程中求出去掉这个割点有多少个连通分块(将iscut[u]=true改为iscut[u]++),
这样子第二次就可以直接找出最多的连通分块了。
#include
#include
#include
#include
#include
#include
#inclu...
分类:
其他好文 时间:
2014-07-08 13:06:23
阅读次数:
145