Dynamic Programming
Dynamic Programming
#include <stdio.h>
#include <string.h>
int dp[MAX][MAX][MAX];
int a[MAX][MAX];
if (k > 0)
{
int skipRight = f(n, m, k - 1, i, j + 1);
int skipDown = f(n, m, k - 1, i + 1, j);
ans = max(ans, skipRight);
ans = max(ans, skipDown);
}
int main() {
int n, m, k;
scanf("%d %d", &n, &m);
scanf("%d", &k);
return 0;
}
Huffman coding
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char c;
int freq;
struct node* left;
struct node* right;
} Node;
Node* pq[MAX_SIZE];
int pq_size = 0;
void insertPQ(Node* n)
{
pq[pq_size++] = n;
for (int i = pq_size - 1; i > 0; i--)
{
Node* pollPQ()
{
pq[i-1] = pq[i];
}
pq_size--;
return n;
}
if (root->c != '$')
{
code[depth] = '\0';
printf("%c %s %d\n", root->c, code, root->freq);
}
if (root->left != NULL)
{
code[depth] = '0';
printCodes(root->left, code, depth + 1);
}
if (root->right != NULL)
{
code[depth] = '1';
printCodes(root->right, code, depth + 1);
}
}
void levelOrder(Node* root)
{
Node* queue[MAX_SIZE];
int front = 0, rear = 0;
queue[rear++] = root;
printf("\n");
}
int main() {
char s[1000];
printf("Enter a string:
"); fgets(s, sizeof(s),
stdin); s[strcspn(s, "\n")]
= '\0';
freq[(unsigned char)s[i]]++;
}
if (freq[i] > 0) {
insertPQ(createNode((char)i, freq[i]));
}
}
return 0;
}
Rabin karp
#include <stdio.h>
#include <string.h>
ph = (p[i] + d * ph) % q;
th = (t[i] + d * th) % q;
}
int main()
{
char t[MAX], p[MAX];
return 0;
}