Skip to content

Instantly share code, notes, and snippets.

@truncs
Created March 14, 2012 23:25
Show Gist options
  • Save truncs/2040357 to your computer and use it in GitHub Desktop.
Save truncs/2040357 to your computer and use it in GitHub Desktop.
Parallel Programming
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
int n;
cin>>n;
int D[n][n], I[n][n], G[n][n];
const int g_e = 1;
const int g_i = 2;
char s1[n];
char s2[n];
cin.getline(s1, n);
cin.getline(s2, n);
// Forward Pass
for (int i = 0; i < n; ++i)
{
for (int j=0; j< n; ++j)
{
if (i == 0 && j == 0)
G[i][j] = 0;
if (i == 0 && j > 0) {
D[i][j] = G[i][j] + g_e;
G[i][j] = g_i + g_e *j;
}
else
D[i][j] = min(D[i - 1][j] + g_e, G[i - 1][j] + g_i);
if ( i > 0 && j == 0) {
I[i][j] = G[i][j] + g_e;
G[i][j] = g_i + g_e *i;
}
else
I[i][j] = min(I[i][j -1] + g_e, G[i][j - 1] + g_i);
if (i > 0 && j > 0) {
int s_cost = s1[i] == s2[j] ? 1 : 0;
int temp = min(D[i][j], I[i][j]);
G[i][j] = min(G[i -1][j -1] + s_cost, temp);
}
}
}
// Backward pass
int i = n -1;
int j = n - 1;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment