算法分析
hotmocha
这个作者很懒,什么都没留下…
展开
-
kmp算法整理
模式匹配index(StringS,String T,int pos)T称为模式串S称为主串简单的想法:从主串的i位置开始匹配,逐一比较,如果当T完成之前都匹配,说明i就是匹配T的开始位置。代码: int Index1(string s,string t,int& pos) { int i,j; for(i=0;i<=s.size()-t.size();i++原创 2012-07-11 08:21:23 · 442 阅读 · 0 评论 -
Anagrams by Stack--zju
Sample InputmadamadammbahamabahamalongshortericriceSample Output[i i i i o o o i o oi i i i o o o o i oi i o i o i o i o oi i o i o i o o i o][i o i i i o o i i o o o原创 2012-07-20 18:48:25 · 433 阅读 · 0 评论 -
STL中的全排列 --好玩
#include #include using namespace std; int main() { 屏幕剪辑的捕获时间: 2012-5-31 9:45 int a[3]={1,2,3}; int i; do { for(i=0;i<=2;i++) printf("%d ",a[i]);原创 2012-07-20 18:51:30 · 377 阅读 · 0 评论 -
1025-Wooden Sticks
经典的最长上升子序列:O(m*m) ---> O(m*logm)#include #includeusing namespace std; int cases;struct Node{ int L,W; bool operator<(const Node &node) const { if(L!=node.L) return (L<node.L); else原创 2012-07-20 18:39:53 · 486 阅读 · 0 评论 -
1005 Jugs-zju
也是一道DFS的题目,但是要注意保存搜过的状态,不然会死循环的!!!#include #include#include#includeusing namespace std; vector v;//a->b :'A' , b->a:'B' , fill a: 'C' , fill b: 'D' , empty a:'E', empty b:'F' vector reca,re原创 2012-07-20 18:44:03 · 442 阅读 · 0 评论 -
Fire Net
以前本科的时候打死没有写出来,现在可以了。。。。#include#includeusing namespace std;string map[5];int n;bool CanPut(int i,int j){ for(int k=i-1;k>=0;k--) { if(map[k][j]=='#') return false; else if(map[k][j]=原创 2012-07-20 18:49:20 · 636 阅读 · 0 评论 -
1008-Gnome Tetravex -zju
经典的DFS,注意使用map[MAX_NODE][MAX_NODE]保存地图:#include #includeusing namespace std; struct Node{ int top,right,buttom,left; bool operator==(const Node &temp) { return (temp.top==top && temp.righ原创 2012-07-20 18:42:05 · 512 阅读 · 0 评论 -
LeetCode Palindrome Partitioning II
Palindrome Partitioning IIMar 113297 / 47208Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.F原创 2013-09-30 19:13:39 · 648 阅读 · 0 评论