From 432f364971e81a2cb81e95ce91e0d931c0a72515 Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sat, 7 May 2016 19:51:40 +0800 Subject: [PATCH 1/7] Create 1284_cnblogs.cpp From http://www.cnblogs.com/qiufeihai/archive/2012/09/11/2680840.html --- HDOJ/1284_cnblogs.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 HDOJ/1284_cnblogs.cpp diff --git a/HDOJ/1284_cnblogs.cpp b/HDOJ/1284_cnblogs.cpp new file mode 100644 index 0000000..eb1dc4d --- /dev/null +++ b/HDOJ/1284_cnblogs.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +using namespace std; + +const int M = 32768 + 10; + +int dp[M]; + +int main() +{ + int n; + while (~scanf("%d", &n)) + { + memset(dp, 0, sizeof(dp)); + dp[0] = 1; + for (int i = 1; i <= 3; i++) + { + for (int j = 1; j <= n; j++) + { + dp[j] += dp[j - i]; + } + } + + printf("%d\n", dp[n]); + } + return 0; +} From 1701104c481f11a585ba489e6477c4ac3de8efa3 Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sat, 7 May 2016 19:53:53 +0800 Subject: [PATCH 2/7] Create 1028_cnblogs.cpp http://www.cnblogs.com/qiufeihai/archive/2012/09/11/2680840.html --- HDOJ/1028_cnblogs.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 HDOJ/1028_cnblogs.cpp diff --git a/HDOJ/1028_cnblogs.cpp b/HDOJ/1028_cnblogs.cpp new file mode 100644 index 0000000..8d8701c --- /dev/null +++ b/HDOJ/1028_cnblogs.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +using namespace std; + +const int M = 120 + 10; + +int dp[M]; + +int main() +{ + int n; + while (~scanf("%d", &n)) + { + + memset(dp, 0, sizeof(dp)); + dp[0] = 1; + + for (int i = 1; i <= n; i++) + { + for (int j = i; j <= n; j++) + { + dp[j] += dp[j - i]; + } + } + + printf("%d\n", dp[n]); + } + return 0; +} From 94ffd5d4820bc2d63411a1f8e34c98120282936e Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sat, 7 May 2016 19:55:59 +0800 Subject: [PATCH 3/7] Create 1398_cnblogs.cpp From http://www.cnblogs.com/qiufeihai/archive/2012/09/11/2680840.html --- HDOJ/1398_cnblogs.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 HDOJ/1398_cnblogs.cpp diff --git a/HDOJ/1398_cnblogs.cpp b/HDOJ/1398_cnblogs.cpp new file mode 100644 index 0000000..3c489d4 --- /dev/null +++ b/HDOJ/1398_cnblogs.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include +using namespace std; + +const int M = 300 + 10; + +int dp[M]; + +int main() +{ + int n; + while (~scanf("%d", &n), n) + { + + memset(dp, 0, sizeof(dp)); + dp[0] = 1; + + int max = (int)sqrt(n * 1.0); + for (int i = 1; i <= max; i++) + { + for (int j = i * i; j <= n; j++) + { + dp[j] += dp[j - i * i]; + } + } + + printf("%d\n", dp[n]); + } + return 0; +} From aefa23377a9ae6072fcd9a92d0f667d202f1559e Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sat, 7 May 2016 19:57:19 +0800 Subject: [PATCH 4/7] Create 2069_cnblogs.cpp From http://www.cnblogs.com/qiufeihai/archive/2012/09/11/2680840.html --- HDOJ/2069_cnblogs.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 HDOJ/2069_cnblogs.cpp diff --git a/HDOJ/2069_cnblogs.cpp b/HDOJ/2069_cnblogs.cpp new file mode 100644 index 0000000..2f90302 --- /dev/null +++ b/HDOJ/2069_cnblogs.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +using namespace std; + +const int M = 300 + 10; + +int dp[111][M]; +int c[] = {0, 1, 5, 10, 25, 50}; + +int main() +{ + //freopen("in.txt", "r", stdin); + int n; + while (~scanf("%d", &n)) + { + + memset(dp, 0, sizeof(dp)); + dp[0][0] = 1; + + for (int i = 1; i <= 5; i++)//枚举硬币总类 + { + for (int num = 1; num <= 100; num++)//枚举硬币个数 + { + for (int j = c[i]; j <= n; j++)//枚举容量 + { + + dp[num][j] += dp[num - 1][j - c[i]]; + } + } + } + + + int ans = 0; + for (int i = 0; i <= 100; i++)//累加答案 + { + ans += dp[i][n]; + } + + printf("%d\n", ans); + } + return 0; +} From f6af6a77a4bf43098c2d7f05992b6c7a416dc40f Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sat, 7 May 2016 20:06:34 +0800 Subject: [PATCH 5/7] Create 1075_cnblogs.cpp From http://www.cnblogs.com/qiufeihai/archive/2012/10/20/2732449.html --- HDOJ/1075_cnblogs.cpp | 142 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 HDOJ/1075_cnblogs.cpp diff --git a/HDOJ/1075_cnblogs.cpp b/HDOJ/1075_cnblogs.cpp new file mode 100644 index 0000000..be9fbcf --- /dev/null +++ b/HDOJ/1075_cnblogs.cpp @@ -0,0 +1,142 @@ +#include +#include +#include +using namespace std; + + + +struct Node +{ + struct Node *child[26]; + int perfixNum; + bool isWord; + char ansChar[111]; +}; + +Node *root, *pNode; + + +void Init() +{ + root = new Node; + for (int i = 0; i < 26; i++) + { + root->child[i] = NULL; + } +} + +void Insert(char word[], char ansChar[]) +{ + int len = strlen(word); + Node *pNode = root; + for (int i = 0; i < len; i++) + { + if (pNode->child[word[i] - 'a'] == NULL) + { + Node *newNode = new Node; + newNode->perfixNum = 1; + newNode->isWord = 0; + for (int j = 0; j < 26; j++) + { + newNode->child[j] = NULL; + } + + pNode->child[word[i] - 'a'] = newNode; + } + else + { + pNode->child[word[i] - 'a']->perfixNum++; + } + + pNode = pNode->child[word[i] - 'a']; + if(i == len - 1) + { + pNode->isWord = 1; + strcpy(pNode->ansChar, ansChar); + } + } +} + +bool Find(char word[]) +{ + int len = strlen(word); + pNode = root; + int i; + for (i = 0; i < len; i++) + { + if (pNode->child[word[i] - 'a'] != NULL) + { + pNode = pNode->child[word[i] - 'a']; + } + else + { + break; + } + } + + //字典中存在该单词 + if (i == len && pNode->isWord == 1) + { + return 1; + } + else + { + return 0; + } +} + + + + +int main() +{ + char getChar[11]; + gets(getChar); + char str1[33], str2[33]; + Init(); + while (scanf("%s%s", str1, str2), str1[0] != 'E') + { + + Insert(str2, str1);//插入,单词,单词的翻译 + } + + getchar(); + char ansStr[3333]; + char saveStr[33]; + while (gets(ansStr), ansStr[0] != 'E') + { + int i; + int k = 0; + for (i = 0; i < strlen(ansStr); i++) + { + if (ansStr[i] < 'a' || ansStr[i] > 'z') + { + if (ansStr[i - 1] >= 'a' && ansStr[i - 1] <= 'z') + { + saveStr[k] = '\0'; + k = 0; + if (Find(saveStr)) + { + printf("%s", pNode->ansChar);//如果字典中存在该单词,则输出它的翻译 + } + else + { + + printf("%s", saveStr);//字典中不存在该单词,输出原单词 + } + } + + printf("%c", ansStr[i]); + + } + else + { + saveStr[k++] = ansStr[i];//保存单词 + } + } + puts(""); + } + + + return 0; +} From 2cd2040d4f2171bdc8ced2a36590432964636d8a Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sat, 7 May 2016 20:16:01 +0800 Subject: [PATCH 6/7] Create 1159_MyCodeBattle.cpp From https://vijos.org/p/1159/solution --- VIJOS/1159_MyCodeBattle.cpp | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 VIJOS/1159_MyCodeBattle.cpp diff --git a/VIJOS/1159_MyCodeBattle.cpp b/VIJOS/1159_MyCodeBattle.cpp new file mode 100644 index 0000000..0ab6566 --- /dev/null +++ b/VIJOS/1159_MyCodeBattle.cpp @@ -0,0 +1,57 @@ +#include +#define LL long long +using namespace std; +const int VMAXN = 2e4 + 10; +const int TMAXN = 100 + 10; +const int INF = 0x3f3f3f3f; + +int num[TMAXN], dp[VMAXN], k, n, m; +int ans[TMAXN]; + +bool Check(int sum) +{ + int &cur = dp[sum]; + if (cur != -1) + return cur; + if (sum == 0) + return cur = 1; + for (int i = 0; i < k; i++) + if (sum >= ans[i] && Check(sum - ans[i])) + return cur = 1; + return cur = 0; +} + +void DFSID(int cur, int dep) +{ + if (dep == k) + { + memset(dp, -1, sizeof dp); + if (Check(n)) + { + printf("%d", k); + for (int i = 0; i < dep; i++) + printf(" %d", ans[i]); + puts(""); + exit(0); + } + return; + } + if (cur >= m) + return; + ans[dep] = num[cur]; + DFSID(cur + 1, dep + 1); + DFSID(cur + 1, dep); +} + +int main() +{ + //freopen("input.txt", "r", stdin); + int i, j; + scanf("%d%d", &n, &m); + for (i = 0; i < m; i++) + scanf("%d", &num[i]); + sort(num, num + m); + for (k = 1; k <= m; k++) + DFSID(0, 0); + return 0; +} From cf696db349ed2d660b6b2a841d96eca44bcb51de Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sat, 7 May 2016 20:16:58 +0800 Subject: [PATCH 7/7] Create 1061_MyCodeBattle.cpp From https://vijos.org/p/1159/solution --- QUSTOJ/1061_MyCodeBattle.cpp | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 QUSTOJ/1061_MyCodeBattle.cpp diff --git a/QUSTOJ/1061_MyCodeBattle.cpp b/QUSTOJ/1061_MyCodeBattle.cpp new file mode 100644 index 0000000..9c8c9e9 --- /dev/null +++ b/QUSTOJ/1061_MyCodeBattle.cpp @@ -0,0 +1,57 @@ +#include +#define LL long long +using namespace std; +const int VMAXN = 2e4 + 10; +const int TMAXN = 100 + 10; +const int INF = 0x3f3f3f3f; + +int num[TMAXN], dp[VMAXN], k, n, m; +int ans[TMAXN]; + +bool Check(int sum) +{ + int &cur = dp[sum]; + if (cur != -1) + return cur; + if (sum == 0) + return cur = 1; + for (int i = 0; i < k; i++) + if (sum >= ans[i] && Check(sum - ans[i])) + return cur = 1; + return cur = 0; +} + +void DFSID(int cur, int dep) +{ + if (dep == k) + { + memset(dp, -1, sizeof dp); + if (Check(n)) + { + printf("%d", k); + for (int i = 0; i < dep; i++) + printf(" %d", ans[i]); + puts(""); + exit(0); + } + return; + } + if (cur >= m) + return; + ans[dep] = num[cur]; + DFSID(cur + 1, dep + 1); + DFSID(cur + 1, dep); +} + +int main() +{ + //freopen("input.txt", "r", stdin); + int i, j; + scanf("%d%d", &n, &m); + for (i = 0; i < m; i++) + scanf("%d", &num[i]); + sort(num, num + m); + for (k = 1; k <= m; k++) + DFSID(0, 0); + return 0; +}