Q:

Find all paths of exact length and cost in graph

I'm currently in the middle of an optimization problem. I'm using dynamic programming and after I'm done with computations, I'm left with N x N matrix that says: if you take mat[i][j] then the value is cost of traveling from i to j == an adjacency matrix.
I also have access to two variables, K and C, which could be interpreted as length of path and cost of path, respectively.
So is there an algorithm, that can find all paths that have length K and cost C?
EDIT:
Here is an sample of adjacency matrix. The path is from 0 -> 8, cost is 48 and length is 3.
So for example, one valid path would be: 0->3 (15), 3->6 (15 + 13), 6->8 (15 + 13 + 20 = 48). Another might be : 0->4 (20), 4->6 (20 + 8), 6 -> 8 (20 + 8 + 20 = 48).
Non-valid path might include: 0->1(8), 1->2(8 + 4), 2->3(8 + 4 + 3), 3->4 (8 + 4 + 3 +5), ..., but length greater than 3, so that is invalid, same thing 0->8 has cost 48, but length 1.
    1   2   3   4   5   6   7   8
---------------------------------
0:  8  12  15  20  26  28  37  48
1:----  4   7  12  18  20  29  40
2:--------  3   8  14  16  25  36
3:------------  5  11  13  22  33
4:----------------  6   8  17  28
5:--------------------  2  11  22
6:------------------------  9  20
7:---------------------------- 11

Actually, looking at it now, I see I have to rephrase my question. The number of vertices is determined during input from user, so is the length and cost. You always travel from first to last vertex. No matter what path you take (ignoring length now), getting from first to last vertex always has cost C, only thing that varies is length.
So the new (and better) question is, how to find all paths from first vertex to last, with length K?  

A:

OP says:  You always travel from first to last vertex. So:

for any i->j, the index j must be greater than i.

And as the example (and according to the OP's explaination), the cost of edges is linear additive. It mean that: 

mat[i][k] + mat[k][j] = mat[i][j]

So:

C(i->j) == C if and only if mat[i][j] == C.

Assuming there exists mat[i][j] == C and j-i<=K, the problem could be simplified to select K-1 nodes from i+1 to j-1, and list all the combinations. You could simply do this by Algorithm to return all combinations of k elements from n.

Here I wrote a code to solve your example in python for test:
N = 9
mat = [None] * (N-1)
mat [0] =[None,    8,   12,   15,   20,   26,   28,   37,   48]
mat [1] =[None, None,    4,    7,   12,   18,   20,   29,   40]
mat [2] =[None, None, None,    3,    8,   14,   16,   25,   36]
mat [3] =[None, None, None, None,    5,   11,   13,   22,   33]
mat [4] =[None, None, None, None, None,    6,    8,   17,   28]
mat [5] =[None, None, None, None, None, None,    2,   11,   22]
mat [6] =[None, None, None, None, None, None, None,    9,   20]
mat [7] =[None, None, None, None, None, None, None, None,   11]

def xcombination(seq,length):
    if not length:
        yield []
    else
        for i in xrange(len(seq)):
            for result in xcombination(seq[i+1:],length-1):
                yield [seq[i]]+result

def find_path(C, K):
    i_j = []
    paths = []
    for i in range(N):
        for j in range(i+1, N):
            if mat[i][j] == C:
                i_j.append([i, j])
    for p in i_j:
        if p[1]-p[0] >= K:
            paths += [[p[0]]+i+[p[1]] for i in xcombination(range(p[0]+1, p[1]), K-1)]
    return paths

paths = find_path(48, 3)
for path in paths:
    for step in range(len(path)-1):
        print str(path[step])+"->"+str(path[step+1])+"("+str(mat[path[step]][path[step+1]])+") ", 
    print

The output answer to your example:
0->1(8)      1->2(4)      2->8(36)
0->1(8)      1->3(7)      3->8(33)
0->1(8)      1->4(12)      4->8(28)
0->1(8)      1->5(18)      5->8(22)
0->1(8)      1->6(20)      6->8(20)
0->1(8)      1->7(29)      7->8(11)
0->2(12)      2->3(3)      3->8(33)
0->2(12)      2->4(8)      4->8(28)
0->2(12)      2->5(14)      5->8(22)
0->2(12)      2->6(16)      6->8(20)
0->2(12)      2->7(25)      7->8(11)
0->3(15)      3->4(5)      4->8(28)
0->3(15)      3->5(11)      5->8(22)
0->3(15)      3->6(13)      6->8(20)
0->3(15)      3->7(22)      7->8(11)
0->4(20)      4->5(6)      5->8(22)
0->4(20)      4->6(8)      6->8(20)
0->4(20)      4->7(17)      7->8(11)
0->5(26)      5->6(2)      6->8(20)
0->5(26)      5->7(11)      7->8(11)
0->6(28)      6->7(9)      7->8(11)       

