精华内容
下载资源
问答
  • DFA

    2016-10-06 00:41:01
    最纯粹的Trie图题目 #include #include #include #include #include using namespace std; struct Node { Node* son[26]; Node* prev; bool badNode; Node() { memset(son, 0, sizeof(son));...



    最纯粹的Trie图题目

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<string>
    #include<queue>
    using namespace std;
    
    struct Node
    {
    	Node* son[26];
    	Node* prev;
    	bool badNode;
    
    	Node()
    	{
    		memset(son, 0, sizeof(son));
    		prev = NULL;
    		badNode = false;
    	}
    };
    
    int ncount;
    
    Node tree[200];
    
    void insert(char * s)
    {
    	Node* p = tree;
    
    	for (int i = 0; s[i] != '\0'; i++)
    	{
    		if (p->son[s[i] - 'a'] == NULL)
    			p->son[s[i] - 'a'] = tree + ncount++;
    
    		p = p->son[s[i] - 'a'];
    	}
    	p->badNode = true;
    }
    
    void buildDfa()
    {
    
    	deque<Node*> q;
    
    	for (int i = 0; i < 26; i++)
    	{
    		if (tree[0].son[i])
    		{
    			tree[0].son[i]->prev = tree;
    			q.push_back(tree[0].son[i]);
    		}
    	}
    
    	while (!q.empty())
    	{
    		Node* p = q.front();
    		q.pop_front();
    
    		for (int i = 0; i < 26; i++)
    		{
    			Node *p2 = p->son[i];
    			if (p2)
    			{
    				Node * prev = p->prev;
    				while (prev)
    				{
    					if (prev->son[i])
    					{
    						p2->prev = prev->son[i];
    						if (prev->son[i]->badNode)
    							p2->badNode = true;
    						break;
    					}
    					prev = prev->prev;
    				}
    				if (prev == NULL)
    					p2->prev = tree;
    				q.push_back(p2);
    			}
    		}
    	}
    }
    
    bool searchDfa(char *s)
    {
    	Node *p = tree;
    	for (int i = 0; s[i] != '\0'; i++)
    	{
    		while (p)
    		{
    			if (p->son[s[i] - 'a'])
    			{
    				p = p->son[s[i] - 'a'];
    				if (p->badNode)
    					return 1;
    				break;
    			}
    			p = p->prev;
    		}
    		if (p == NULL)
    			p = tree;
    
    	}
    	return false;
    }
    
    
    int main()
    {
    	ncount = 1;
    	int n, m;
    
    	char str[100];
    
    	scanf("%d%d", &n, &m);
    
    	for (int i = 0; i < n; i++)
    	{
    		scanf("%s", str);
    		insert(str);
    	}
    	buildDfa();
    	for (int i = 0; i < m; i++)
    	{
    		scanf("%s", str);
    		if (searchDfa(str))
    			printf("1\n");
    		else
    			printf("0\n");
    	}
    
    
    }
    


    POJ 3987 病毒查找

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<string>
    #include<queue>
    #include<ctype.h>
    #include<math.h>
    using namespace std;
    
    
    
    struct Node
    {
    	Node* last;
    	bool isCalc;
    	int whichWord;
    	Node *prev, *son[26];
    };
    
    Node tree[250 * 1000 + 100];
    
    queue<Node*> q;
    int ncount;
    
    char programStr[5100010];
    
    int ansCount;
    
    int visited[250 * 1000 + 100];
    
    int n;
    
    inline Node* newnode()
    {
    	tree[ncount].last = NULL;
    	tree[ncount].isCalc = false;
    	tree[ncount].prev = NULL;
    	tree[ncount].whichWord = -1;
    	for (int i = 0; i < 26; i++)
    	{
    		tree[ncount].son[i] = NULL;
    	}
    	return tree + ncount++;
    }
    
    
    inline void insert(char * s, int whichWord)
    {
    	Node* p = tree;
    
    	for (int i = 0; s[i] != '\0'; i++)
    	{
    		if (p->son[s[i] - 'A'] == NULL)
    			p->son[s[i] - 'A'] = newnode();
    
    		p = p->son[s[i] - 'A'];
    	}
    	p->whichWord = whichWord;
    
    }
    
    
    void buildDfa()
    {
    
    	for (int i = 0; i < 26; i++)
    	{
    		if (tree[0].son[i])
    		{
    			tree[0].son[i]->prev = tree;
    			q.push(tree[0].son[i]);
    		}
    	}
    
    	while (!q.empty())
    	{
    		Node* p = q.front();
    		q.pop();
    
    
    
    		for (int i = 0; i < 26; i++)
    		{
    			if (p->son[i])
    			{
    				Node *prev = p->prev;
    				while (prev)
    				{
    					if (prev->son[i])
    					{
    						p->son[i]->prev = prev->son[i];
    						if (prev->son[i]->whichWord!=-1)
    						{
    							p->son[i]->last = prev->son[i];
    						}
    						else if (prev->son[i]->last)
    						{
    							p->son[i]->last= prev->son[i]->last;
    						}
    						break;
    					}
    					else
    						prev = prev->prev;
    				}
    				if (prev == NULL)
    					p->son[i]->prev = tree;
    				q.push(p->son[i]);
    			}
    		}
    	}
    }
    
    
    int strToInt(char *s, int n)
    {
    	int sum = 0;
    
    	for (int i = 0; i < n; i++)
    	{
    		sum += (s[i] - '0')*(int)pow(10, n - i - 1);
    	}
    	return sum;
    }
    
    inline void foo(Node * &p, const char &ch)
    {
    	while (p)
    	{
    		if (p->son[ch - 'A'])
    		{
    			p = p->son[ch - 'A'];
    			break;
    		}
    		else
    			p = p->prev;
    	}
    	if (p == NULL)
    		p = tree;
    
    
    
    	if (p->last && p->last->isCalc == false)
    	{
    		Node * temp = p->last;
    		while (temp)
    		{
    			temp->isCalc = true;
    			if(visited[temp->whichWord]==0)
    			{
    				ansCount++;
    				visited[temp->whichWord]=1;
    			}
    			temp = temp->last;
    		}
    	}
    	if (p->whichWord != -1 && p->isCalc == false)
    	{
    		p->isCalc = true;
    		if(visited[p->whichWord]==0)
    		{
    			ansCount++;
    			visited[p->whichWord]=1;
    		}
    	}
    	
    
    	
    }
    
    void searchDfa1(char *s)
    {
    	Node *p = tree;
    	for (int i = 0; s[i] != '\0'; i++)
    	{
    		if (s[i] == '[')
    		{
    			int cnt = 0;
    			i++;
    			int i2 = i;
    			while (isdigit(s[i]))
    			{
    				i++;
    				cnt++;
    			}
    			int q = strToInt(s + i2, cnt);
    
    			while (q--)
    			{
    
    				foo(p, s[i]);
    			}
    			i++;
    		}
    		else
    		{
    			foo(p, s[i]);
    
    		}
    
    
    
    
    
    	}
    }
    
    void searchDfa2(char *s)
    {
    	Node *p = tree;
    	int len = strlen(s);
    	for (int i = len - 1; i >= 0; i--)
    	{
    		if (s[i] == ']')
    		{
    			int cnt = 0;
    			i--;
    			char x = s[i];
    			i--;
    			while (isdigit(s[i]))
    			{
    				i--;
    				cnt++;
    			}
    			int q = strToInt(s + i + 1, cnt);
    
    			while (q--)
    			{
    
    				foo(p, x);
    			}
    
    		}
    		else
    		{
    			foo(p, s[i]);
    
    		}
    
    
    
    
    
    	}
    }
    
    
    
    
    int main()
    {
    	int t;
    	scanf("%d", &t);
    	while (t--)
    	{
    		memset(visited,0,sizeof(visited));
    		ncount = 0;
    		ansCount = 0;
    		newnode();//初始化根节点
    		scanf("%d", &n);
    
    		char str[1010];
    		for (int i = 0; i < n; i++)
    		{
    			scanf("%s", str);
    			insert(str, i);
    		}
    
    		scanf("%s", programStr);
    
    
    		buildDfa();
    
    
    		searchDfa1(programStr);
    
    		searchDfa2(programStr);
    
    		printf("%d\n", ansCount);
    
    
    	}
    
    
    
    
    
    }
    
    


    POJ 1204 字谜

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<string>
    #include<queue>
    using namespace std;
    
    #define INF 1001
    
    struct Node
    {
    	int whichWord;
    	Node *prev, *son[26];
    };
    
    Node tree[INF*INF];
    
    queue<Node*> q;
    
    struct Location
    {
    	int r, c, d;
    };
    
    Location ans[1001];
    
    int  r, c, w, ncount;
    
    
    char graph[INF][INF], tp[INF];
    
    
    int dx[8] = { -1,-1,0,1,1,1 ,0 ,-1 };
    int dy[8] = { 0 ,1 ,1,1,0,-1,-1,-1 };
    
    Node* newnode()
    {
    	tree[ncount].prev = NULL;
    	tree[ncount].whichWord = -1;
    	for (size_t i = 0; i < 26; i++)
    	{
    		tree[ncount].son[i] = NULL;
    	}
    	return tree + ncount++;
    }
    
    
    void insert(char * s, int whichWord)
    {
    	Node* p = tree;
    	int len = strlen(s);
    
    	for (int i = len - 1; i >= 0; i--)
    	{
    		if (p->son[s[i] - 'A'] == NULL)
    			p->son[s[i] - 'A'] = newnode();
    
    		p = p->son[s[i] - 'A'];
    	}
    	p->whichWord = whichWord;
    }
    
    
    void buildDfa()
    {
    	Node *p = tree;
    	for (int i = 0; i < 26; i++)
    	{
    		if (p->son[i])
    		{
    			p->son[i]->prev = tree;
    			q.push(p->son[i]);
    		}
    	}
    
    	while (!q.empty())
    	{
    		p = q.front();
    		q.pop();
    
    
    
    		for (int i = 0; i < 26; i++)
    		{
    			if (p->son[i])
    			{
    				Node *prev = p->prev;
    				while (prev)
    				{
    					if (prev->son[i])
    					{
    						p->son[i]->prev = prev->son[i];
    						break;
    					}
    					else
    						prev = prev->prev;
    				}
    				if (prev == NULL)
    					p->son[i]->prev = tree;
    				q.push(p->son[i]);
    			}
    		}
    	}
    }
    
    
    void searchDfa(int rr, int cc, int kk)
    {
    	int nx = rr;
    	int ny = cc;
    	Node *p = tree;
    
    	for (; 0 <= nx && nx < r && 0 <= ny && ny < c; nx += dx[kk], ny += dy[kk])
    	{
    		while (p)
    		{
    			if (p->son[graph[nx][ny] - 'A'])
    			{
    				p = p->son[graph[nx][ny] - 'A'];
    				break;
    			}
    			else
    				p = p->prev;
    		}
    		if (p == NULL)
    			p = tree;
    
    
    		Node* temp = p;
    		while (temp != tree)
    		{
    			if (p->whichWord != -1)
    			{
    				ans[temp->whichWord].r = nx;
    				ans[temp->whichWord].c = ny;
    				ans[temp->whichWord].d = kk;
    				//temp->whichWord = -1;
    			}
    			temp = temp->prev;
    		}
    	}
    }
    
    
    void search()
    {
    	for (int i = 0; i < c; i++)
    	{
    		searchDfa(0, i, 5);
    		searchDfa(0, i, 4);
    		searchDfa(0, i, 3);
    
    		searchDfa(r - 1, i, 7);
    		searchDfa(r - 1, i, 0);
    		searchDfa(r - 1, i, 1);
    
    	}
    
    	for (int i = 0; i < r; i++)
    	{
    		searchDfa(i, 0, 1);
    		searchDfa(i, 0, 2);
    		searchDfa(i, 0, 3);
    
    		searchDfa(i, c - 1, 7);
    		searchDfa(i, c - 1, 6);
    		searchDfa(i, c - 1, 5);
    	}
    }
    
    
    
    int main()
    {
    
    	while (scanf("%d%d%d", &r, &c, &w) == 3)
    	{
    		ncount = 1;
    		for (int i = 0; i < r; i++)
    			scanf("%s", graph[i]);
    
    		for (int i = 0; i < w; i++)
    		{
    			scanf("%s", tp);
    			insert(tp, i);
    		}
    
    		buildDfa();
    
    		search();
    
    		for (int i = 0; i < w; i++)
    		{
    			printf("%d %d %c\n", ans[i].r, ans[i].c, 'A' + (ans[i].d + 4) % 8);
    		}
    	}
    
    }
    
    
    
    


    POJ 3691 DNA repair

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<string>
    #include<queue>
    #include<ctype.h>
    #include<math.h>
    using namespace std;
    
    
    int chge(char ch)
    {
    	switch (ch)
    	{
    	case 'A':return 0;
    	case 'C':return 1;
    	case 'G':return 2;
    	case 'T':return 3;
    	default:
    		exit(1);
    	}
    }
    
    
    
    struct Node
    {
    	int prev;
    	int child[4];
    	bool badNode;
    };
    
    Node tree[20 * 50 + 100];
    
    queue<int> q;
    int ncount;
    int n;
    char pstr[25];
    char str[1010];
    
    int dp[1000 + 10][20 * 50 + 100];
    
    int newnode()
    {
    	tree[ncount].badNode = false;
    	tree[ncount].prev = -1;
    	for (size_t i = 0; i < 4; i++)
    	{
    		tree[ncount].child[i] = -1;
    	}
    	return ncount++;
    }
    
    void insert()
    {
    	int p = 0;
    
    	for (int i = 0; pstr[i] != '\0'; i++)
    	{
    		if (tree[p].child[chge(pstr[i])] == -1)
    		{
    			tree[p].child[chge(pstr[i])] = newnode();
    		}
    
    		p = tree[p].child[chge(pstr[i])];
    	}
    	tree[p].badNode = true;
    }
    
    
    void buildDfa()
    {
    
    	for (int i = 0; i < 4; i++)
    	{
    		if (tree[0].child[i] != -1)
    		{
    			tree[tree[0].child[i]].prev = 0;
    			q.push(tree[0].child[i]);
    		}
    		else
    		{
    			tree[0].child[i] = 0;
    		}
    	}
    
    	while (!q.empty())
    	{
    		int p = q.front();
    		q.pop();
    
    
    
    		for (int i = 0; i < 4; i++)
    		{
    			if (tree[p].child[i] != -1)
    			{
    				int prev = tree[p].prev;
    				while (prev != -1)
    				{
    					if (tree[prev].child[i] != -1)
    					{
    						tree[tree[p].child[i]].prev = tree[prev].child[i];
    						if (tree[tree[prev].child[i]].badNode)
    							tree[tree[p].child[i]].badNode = true;
    						break;
    					}
    					else
    						prev = tree[prev].prev;
    				}
    				if (prev == -1)
    				{
    					tree[tree[p].child[i]].prev = 0;
    
    				}
    				q.push(tree[p].child[i]);
    			}
    			else
    			{
    				tree[p].child[i] = tree[tree[p].prev].child[i];
    			}
    		}
    	}
    }
    
    
    int main()
    {
    
    	int caseCnt = 1;
    	while (scanf("%d", &n) == 1 && n != 0)
    	{
    
    		ncount = 0;
    		newnode();
    
    
    		for (int i = 0; i < 1000 + 10; i++)
    			for (int j = 0; j < 20 * 50 + 100; j++)
    				dp[i][j] = 1 << 30;
    
    
    		for (int i = 0; i < n; i++)
    		{
    			scanf("%s", pstr);
    			insert();
    		}
    		scanf("%s", str);
    		buildDfa();
    
    		int len = strlen(str);
    		dp[0][0] = 0;
    		for (int i = 1; i <= len; i++)
    		{
    			for (int j = 0; j < ncount; j++)
    			{
    				if (dp[i - 1][j] != 1 << 30)
    				{
    					for (int k = 0; k < 4; k++)
    					{
    						if (tree[tree[j].child[k]].badNode == false)
    						{
    							if (chge(str[i - 1]) == k)
    								dp[i][tree[j].child[k]] = min(dp[i][tree[j].child[k]], dp[i - 1][j]);
    							else
    								dp[i][tree[j].child[k]] = min(dp[i][tree[j].child[k]], dp[i - 1][j] + 1);
    						}
    					}
    				}
    			}
    		}
    
    		int ans = 1 << 30;
    		for (int i = 0; i < ncount; i++)
    			if (tree[i].badNode == false && ans>dp[len][i])
    			{
    				ans = dp[len][i];
    			}
    
    		printf("Case %d: ", caseCnt++);
    		if (ans == 1 << 30)
    			printf("-1\n");
    		else
    			printf("%d\n", ans);
    	}
    }
    
    
    



    POJ 1625 不包含单词的语句个数

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<string>
    #include<queue>
    #include<ctype.h>
    #include<map>
    #include<math.h>
    using namespace std;
    
    
    struct Node
    {
    	int prev;
    	int child[55];
    	bool badNode;
    };
    
    Node tree[10 * 50 + 100];
    
    queue<int> q;
    int ncount;
    
    map<char, int> charToInt;
    int acount;
    
    int n, m, p;
    
    char pstr[15];
    
    
    
    
    int newnode()
    {
    
    	tree[ncount].badNode = false;
    	tree[ncount].prev = -1;
    	for (int i = 0; i < n; i++)
    	{
    		tree[ncount].child[i] = -1;
    	}
    	return ncount++;
    }
    
    void insert()
    {
    	int p = 0;
    
    	for (int i = 0; pstr[i] != '\0'; i++)
    	{
    		if (tree[p].child[charToInt[pstr[i]]] == -1)
    		{
    			tree[p].child[charToInt[pstr[i]]] = newnode();
    		}
    
    		p = tree[p].child[charToInt[pstr[i]]];
    	}
    	tree[p].badNode = true;
    }
    
    
    void buildDfa()
    {
    
    	for (int i = 0; i < n; i++)
    	{
    		if (tree[0].child[i] != -1)
    		{
    			tree[tree[0].child[i]].prev = 0;
    			q.push(tree[0].child[i]);
    		}
    		else
    		{
    			tree[0].child[i] = 0;
    		}
    	}
    
    	while (!q.empty())
    	{
    		int p = q.front();
    		q.pop();
    
    
    
    		for (int i = 0; i < n; i++)
    		{
    			if (tree[p].child[i] != -1)
    			{
    				int prev = tree[p].prev;
    				while (prev != -1)
    				{
    					if (tree[prev].child[i] != -1)
    					{
    						tree[tree[p].child[i]].prev = tree[prev].child[i];
    						if (tree[tree[prev].child[i]].badNode)
    							tree[tree[p].child[i]].badNode = true;
    						break;
    					}
    					else
    						prev = tree[prev].prev;
    				}
    				if (prev == -1)
    				{
    					tree[tree[p].child[i]].prev = 0;
    
    				}
    				q.push(tree[p].child[i]);
    			}
    			else
    			{
    				tree[p].child[i] = tree[tree[p].prev].child[i];
    			}
    		}
    	}
    }
    
    
    struct BigInteger
    {
    	int A[25];
    	enum
    	{
    		MOD = 10000
    	};
    	BigInteger()
    	{
    		memset(A, 0, sizeof(A)); A[0] = 1;
    	}
    	void set(int x)
    	{
    		memset(A, 0, sizeof(A)); A[0] = 1; A[1] = x;
    	}
    	void print()
    	{
    		printf("%d", A[A[0]]);
    		for (int i = A[0] - 1; i > 0; i--)
    		{
    			if (A[i] == 0)
    			{
    				printf("0000"); continue;
    			}
    			for (int k = 10; k*A[i] < MOD; k *= 10) printf("0");
    			printf("%d", A[i]);
    		}
    		printf("\n");
    	}
    	int& operator [] (int p)
    	{
    		return A[p];
    	}
    	const int& operator [] (int p) const
    	{
    		return A[p];
    	}
    	BigInteger operator + (const BigInteger& B)
    	{
    		BigInteger C;
    		C[0] = max(A[0], B[0]);
    		for (int i = 1; i <= C[0]; i++)
    			C[i] += A[i] + B[i], C[i + 1] += C[i] / MOD, C[i] %= MOD;
    		if (C[C[0] + 1] > 0) C[0]++;
    		return C;
    	}
    	BigInteger operator * (const BigInteger& B)
    	{
    		BigInteger C;
    		C[0] = A[0] + B[0];
    		for (int i = 1; i <= A[0]; i++)
    			for (int j = 1; j <= B[0]; j++)
    			{
    				C[i + j - 1] += A[i] * B[j], C[i + j] += C[i + j - 1] / MOD, C[i + j - 1] %= MOD;
    			}
    		if (C[C[0]] == 0) C[0]--;
    		return C;
    	}
    };
    
    int main()
    {
    
    	int caseCnt = 1;
    	while (scanf("%d%d%d", &n, &m, &p) == 3)
    	{
    
    		ncount = 0;
    		newnode();
    		acount = 0;
    
    		BigInteger dp[51][101];
    		dp[0][0].set(1);
    
    
    		scanf("%s", pstr);
    
    		for (int i = 0; pstr[i] != '\0'; i++)
    		{
    			charToInt[pstr[i]] = acount++;
    
    		}
    
    		for (int i = 0; i < p; i++)
    		{
    			scanf("%s", pstr);
    			insert();
    		}
    
    		buildDfa();
    
    
    
    
    		for (int i = 1; i <= m; i++)
    		{
    			for (int j = 0; j < ncount; j++)
    			{
    
    				for (int k = 0; k < n; k++)
    				{
    					if (tree[tree[j].child[k]].badNode == false)
    					{
    						dp[i][tree[j].child[k]] = dp[i][tree[j].child[k]] + dp[i - 1][j];
    					}
    				}
    
    			}
    		}
    
    		BigInteger ans;
    
    		for (int i = 0; i < ncount; i++)
    		{
    
    			ans = ans + dp[m][i];
    		}
    
    		ans.print();
    
    
    	}
    }
    
    
    



    The Book List


    #include<stdio.h>
    #include<map>
    #include<string>
    #include<iostream>
    #include<set>
    using namespace std;
    
    
    
    struct Node
    {
    	map<string, int> category;
    	set<string> book;
    };
    
    Node tree[1508];
    
    int ncount;
    
    
    string address;
    
    
    
    
    void Insert(int cur, int root)
    {
    	int i = cur;
    	string word;
    	while (i < address.size() && address[i] != '/')
    	{
    		word += address[i];
    		i++;
    	}
    
    
    
    	if (address[i] == '/')//category
    	{
    
    
    		if (tree[root].category.count(word) == 0)//不存在这个目录,新建节点
    		{
    			tree[root].category[word] = ++ncount;
    		}
    
    		Insert(i + 1, tree[root].category[word]);
    
    	}
    	else//book
    	{
    
    		tree[root].book.insert(word);
    	}
    
    }
    
    void showSpace(int n)
    {
    	for (int i = 0; i < n; i++)
    		printf("    ");
    }
    
    void show(int depth, int root)
    {
    	for (auto cate : tree[root].category)
    	{
    		showSpace(depth - 1);
    		printf("%s\n", cate.first.c_str());
    		show(depth + 1, cate.second);
    	}
    
    	for (auto b : tree[root].book)
    	{
    		showSpace(depth - 1);
    		printf("%s\n", b.c_str());
    	}
    }
    
    void init()
    {
    	for (int i = 0; i <= ncount; i++)
    	{
    		tree[i].book.clear();
    		tree[i].category.clear();
    	}
    
    	ncount = 0;
    }
    
    int main()
    {
    	int caseCnt = 1;
    	ncount = 0;
    	//freopen("a.txt", "w", stdout);
    	while (getline(cin, address))
    	{
    
    
    		do
    		{
    			if (address == "0")
    			{
    				printf("Case %d:\n", caseCnt++);
    				show(1, 0);
    				init();
    			}
    			else
    				Insert(0, 0);
    
    		} while (getline(cin, address));
    
    		return 0;
    	}
    
    }
    
    
    


    展开全文
  • 摘要:Mobile phones are already approaching penetration rates of close to 80 per cent in some parts of the world. Mobile payments, or "m-payments", are expected to become an important part of retail ...

    摘要:

    Mobile phones are already approaching penetration rates of close to 80 per cent in some parts of the world. Mobile payments, or "m-payments", are expected to become an important part of retail payments. M-payments are defined as payments that are carried out via mobile phone. M-commerce as a wide area could be divided into mobile E-commerce and M-trade area. Different models of mobile payments are proposed considering the physical disposition. Financial service provider is essential mediator among customers, merchants and banks. The iMS specification proposed in this paper enables mobile payments with one click of a button. Different levels of security have to be implemented for small, medium and large transaction of funds.

    展开

    展开全文
  • cascade_rcnn_dconv_c3-c5_r50_fpn_1x_20190125-dfa53166.pth深度学习公开模型文件。使用coco数据集训练。
  • 摘要:Method and apparatus for half folding sequentially and nesting a plurality of paper sheets. The apparatus includes a buckle chute folder, the folder having a first pair of feed rollers rotatable...

    摘要:

    Method and apparatus for half folding sequentially and nesting a plurality of paper sheets. The apparatus includes a buckle chute folder, the folder having a first pair of feed rollers rotatable at a given velocity, and a device for continuously feeding the paper sheets in shingled relationship at a second velocity greater than the given velocity to the feed rollers. The shingled relationship is defined by an overlap of the sheets of at least one-half of the length of the sheets. By using the apparatus and method, any desired number of sheets may be folded sequentially and nested one inside the other.

    展开

    展开全文
  • 教材上的例题复现: 正规式转换为NFA; NFA转换为DFA; 化简DFA

    教材使用《程序设计语言编译原理》-3版,作者:陈火旺、刘春林等。
    用自己的话把教材上的例题复现了一遍,如有不足,请指教。

    NFA :非确定有限自动机;
    DFA :确定有限自动机;

    正规式转NFA

    在这里插入图片描述
    就这么简单。。。

    NFA -> DFA

    在这里插入图片描述
    图3.6 非确定有限自动机

    涉及到课本 P49~P50 讲解的子集法——把 NFA 确定为 DFA 的方法。(下面再解释解释)

    定义

    • M : NFA
    • M’ : 最终得到的 NFA
    • M’’ : DFA
      假定 I 是 M’ 的状态集的子集,
    • ε_CLOSURE(I) : 由 ε 弧连接起来的一个连通分量
      I 的 ε 闭包,包括 I 本身,也包括从其中任意一个状态元素 q 通过任意条 ε 弧可以到达的状态 q’
      在这里插入图片描述
      图3.6 举例:像 ε_CLOSURE({X}) = {X, 5, 1}, ε_CLOSURE({2}) = {2, 6, Y}
      就是由 ε 弧连接起来的一个连通分量
    • Ia : 由 a 弧连接起来的一个连通分量
      Ia = ε_CLOSURE(J),J 中的状态 q’ 是从 I 中任意一个状态 q 通过一条 a 弧可以达到的状态,同时不要忘记通过任意条 ε 弧 到达的状态;
      图3.6 举例 : {5, 3, 1}a = {5, 3, 1, 2, 6, 7},
      分析过程
    原状态通过 a 弧到达的状态
    55
    32
    13

    得到状态集合:{5, 3, 2};

    原状态通过 ε 弧到达的状态
    51
    3\
    26, Y

    最后得到状态集合:{5, 3, 1, 2, 6, 7};
    注意,每个状态,特别是终态,都可以看作有一条 ε 弧连接自己,所以终态只能读取 ε,其它的读取不了。上面有些状态集合里含有终态 Y ,是由前面的状态通过 ε 弧达到的。

    例3.3 NFA 转换为 DFA

    正规式 (a|b)*(aa|bb)(a|b)* 对应的 NFA 如图 3.6 所示,其中 X 为初态,Y 为终态。按照上述过程(子集法)构造出来的状态转换矩阵见表 3.3
    在这里插入图片描述

    表 3.3 对应于例 3.3 中正规式的状态转换矩阵

    构造过程

    把初始状态 X 的 ε 闭包,即 ε_CLOSURE({X}), 现在记为 I,放在第一行第一列,求出Ia, Ib,将出现在右边列(除最左边一列外的所以列),但是没有出现在最左边列的状态集合,添加到最左边列中,重复操作,直到右边列中出现的所有状态集都在最左边列出现过。
    在这里插入图片描述

    重新命名

    在这里插入图片描述
    对表 3.3 中的所有状态子集重新命名,其中含有原终态 Y 的新状态也是终态,标记上双圆圈,得到表 3.4 所列的状态转换矩阵;
    在这里插入图片描述
    表 3.4 对表 3.3 中状态子集重新命名后的状态转换矩阵

    由表 3.4 画出对应的状态图 (图 3.8):
    在这里插入图片描述
    图 3.8 未化简的 DFA

    例 3.6 化简 DFA

    化简图 3.8 表示的 DFA;
    首先把 M 的状态分成两组 :终态组非终态组
    在这里插入图片描述
    得到化简后的图像 (图 3.5):
    在这里插入图片描述
    图 3.5 状态转换图

    展开全文
  • 编译原理-DFA模拟程序

    千次阅读 2020-04-03 12:03:07
    实验1 词法程序设计——DFA模拟程序一、实验目的二、实验内容三、实验环境四、实验内容五、实验原理六、实验代码七、实验结论八、实验存在的问题以及待改进的地方九、实验心得 一、实验目的 编写一个C++语言程序,...
  • DFA算法C#实现

    2020-12-25 15:53:42
    原理搜关键字:DFA算法 基本照抄了原文的JAVA代码,其中vb.net教程应该可以用Dictionary<string,int>来代替Hashtable,但搜到的资料都说Hashtable快得要命,虽然知道他们说的是JAVA环境,但也懒得c#教程改了,...
  • 摘要:A system and method for analyzing the characteristics of a thin film is provided whereby the in-plane birefringence of thin films is determined by measuring the interference fringes in the ...
  • DFA.java 中的 DFA 类实现成员函数 boolean recongnizeString(int move[][], int accept_state[], String word),函数功能和参数说明如下。 函数功能:如果 word 被 move 和 accept_state 所代表的 DFA 识别,...
  • soj-1000. DFA识别语言

    2020-12-28 23:38:27
    =50)和M(M<=26),分别代表DFA的状态数和字母表的字符数。DFA的N个状态用整数0~N-1表示。状态0为起始状态。字母表包含的字符是小写英文字母的前M个字符。接下来的N行,每行有M个整数。其中第i行第j列的数字k,...
  • 1、为什么要用DFA 2、DFA工具类实现 3、性能对比效果 3.1 普通关键字过滤 3.2 DFA关键字过滤 1、为什么要用DFA 2、DFA工具类实现 3、性能对比效果 3.1 普通关键字过滤 JMH代码如下: package ...
  • 46 47 48 static char 49 getNextChar() {50 if (linepos >=bufsize) {51 lineno = 0;52 if (state !=START)53 return ‘ ‘;54 if (get.getline(lineBuf, BUFLEN - 1)) {55 printf("%d: %s\n", columnpos++, ...
  • graphviz安装 [参考文章] 1.python 安装 graphviz pip install graphviz ...NFA 转 DFA 遇到的问题: python引用数据类型赋值时要注意浅拷贝问题,可以使用deepcopy函数解决 list类型不能作为set的元素和dict的键 循
  • 采取的方法是hopcroft的填表法,... 1 #include "nfa_to_dfa.h" 2 int* dfa_diff_matrix; 3 4 int mini_dfa_number;//这个是最小化的 dfa表的索引 5 typedef struct _min_dfa_node 6 { 7 pdfa_edge b...
  • DFA算法:即确定有穷自动机,简单点说就是,它是是通过event和当前的state得到下一个state,即event+state=nextstate。理解为系统中有多个节点,通过传递进入的event,来确定走哪个路由至另一个节点,而节点是有限的...
  • 201. Non Absorbing DFA

    2014-07-30 21:52:00
    题意好难看懂的说。。。  有限状态自动机DFA是这么一个有序组<Σ, U, s, T, phi>;Σ代表输入字符集,表示此... 利用DFA进行字符串识别是要你做这么一件事情:The input of the automation is the string...
  • 词法分析☞DFA语言识别

    千次阅读 2016-09-30 19:24:44
    编译原理的上级代码题目,判断一个语言是否被DFA接受
  • SGU 201 Non Absorbing DFA

    2016-08-01 09:42:04
    学过编译原理的一定知道DFA(确定性有穷自动机)是什么,没学过简单说一下,给定开始状态和结束状态,以及状态转移函数phi,以及是否去掉首字母的标记,跟其他自动机一样,字符串被接受即从开始状态开始,根据首字母...
  • 46 47 48 static char 49 getNextChar() {50 if (linepos >=bufsize) {51 lineno = 0;52 if (state !=START)53 return \' \';54 if (get.getline(lineBuf, BUFLEN - 1)) {55 printf("%d: %s\\n", columnpos++, ...
  • DFA极简化和NFA确定化

    千次阅读 2018-06-15 15:25:15
    最小化DFA说明 整体的步骤是三步: 一,先把正规式转换为NFA(非确定有穷自动机), 二,在把NFA通过“子集构造法”转化为DFA, 三,在把DFA通过“分割法”进行最小化。一步很简单,就是反复运用下图的规则,图1...
  • =50)和M(M<=26),分别代表DFA的状态数和字母表的字符数。DFA的N个状态用整数0~N-1表示。状态0为起始状态。字母表包含的字符是小写英文字母的前M个字符。接下来的N行,每行有M个整数。其中第i行第j列的数字k,...
  • 运用距平、累积离差、非趋势波动DFA法,对长江上游寸滩水文站近50年来河流径流量的年内变化和年际变化时间序列进行了分析,根据DFA指数的变化特性,分析了不同时间尺度下流量序列变化的突变点和幂律关系。...
  • DFA M=({S,U,V,Q},{a,b},f, S, {Q}) 其中f定义为: f(S,a)=U f(V,a)=U f(S,b)=V f(V,b)=Q f(U,a)=Q f(Q,a)=Q f(U,b)=V f(Q,b)=Q DFA的状态转换关系如所示。 编写一个DFA程序,用于判断符号串t是否...
  • DFA(确定的有穷自动机)的化简一、 实验目的二、 实验内容三、 实验环境四、 算法与实验原理五、 实验代码六、 实验结论七、 实验遇到的问题八、 实验心得 一、 实验目的 通过设计、编写和调试将确定的有穷自动机的...
  • 二进制模5的DFA

    2017-03-25 20:53:00
    1 /* 2 已知语言L={x|x∈{0,1}*}且当把x看成二进制时,x模5与0同余,...画出该语言的DFA状态图。 4 s为初始状态,a~e分别代表余0~4,z表示第一个输入为0,t表示0之后还有输入 5 num=5N+k 6 num=2(5N+k)+...
  • java实现敏感词过滤(DFA算法) </h1> <div class="clear"></div> <div class="postBody"> 小Alan在最近的开发中遇到了敏感词过滤,便去网上查阅了很多敏感词过...
  • NFA非有穷自动机,即当前状态识别某个转换条件后到达的后继状态不唯一,这种自动机不便机械实现,而DFA是确定有限状态的自动机,它的状态转换的条件是确定的,且状态数目往往少于NFA,所以DFA能够比较方便的机械实现...
  • Hurst指数以及MF-DFA

    2019-09-26 00:58:42
    现在对于分形市场假说的主要方法论就是 Hurst指数,通过MF-DFA(Multifractal detrended fluctuation analysis)来计算, 具体的可以维基百科一下,大体就是当hurst>0.5时时间序列是一个persistent的过程,当hurst>...
  • nfa转dfa,正式完成

    2019-10-07 19:47:45
    50 if (dfa_hash_table[result].in_use== 0 ) 51 { 52 dfa_hash_table[result].dfa_node_pointer= dfa_node_index; 53 dfa_hash_table[result].in_use= 1 ; 54 hash_name=malloc( sizeof ( char )*...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 6,724
精华内容 2,689
关键字:

dfa50