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; +} 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; +} 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; +} 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; +} 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; +} 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; +} 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; +}