15,923,164 members
Home / Discussions / C / C++ / MFC

# C / C++ / MFC

 Re: Abstract Factory Design/Linked List Problem Richard MacCutchan28-Dec-19 21:49 Richard MacCutchan 28-Dec-19 21:49
 Re: Abstract Factory Design/Linked List Problem Stefan_Lang6-Jan-20 0:22 Stefan_Lang 6-Jan-20 0:22
 queues to find minimum time to serve all. Jiopik27-Dec-19 19:01 Jiopik 27-Dec-19 19:01
 Re: queues to find minimum time to serve all. Richard MacCutchan27-Dec-19 22:01 Richard MacCutchan 27-Dec-19 22:01
 Re: queues to find minimum time to serve all. leon de boer28-Dec-19 14:40 leon de boer 28-Dec-19 14:40
 How to check if USB filter driver be installed by MFC? yufengchien26-Dec-19 22:19 yufengchien 26-Dec-19 22:19
 Re: How to check if USB filter driver be installed by MFC? Richard MacCutchan26-Dec-19 23:44 Richard MacCutchan 26-Dec-19 23:44
 Knight move, right direction, dynamic programming to get the maximum cost path from top left to right bottom. Jiopik25-Dec-19 0:25 Jiopik 25-Dec-19 0:25
 I am trying to solve this problem through dynamic programming: You are given a matrix of n rows and m columns. There’s an integer number on each cell of the board and the rabbit staying at the upper-left corner. Collect the greatest sum possible, such that the rabbit can move in only two directions: 2 cells to the right and 1 cell down (x+2, y+1); 2 cells down and 1 cell to the right (x+1, y+2); Input: The first line contains two naturals n and m (1 ≤ n, m ≤ 10^3) – the quantity of rows and columns of the matrix. The next n lines contain m numbers – the values of the matrix elements. The upper-left corner’s coordinates are (1, 1), the lower-right corner’s – (n, m). Output: The greatest sum possibly collected. If the r rabbit can’t reach the lower-right corner, output «-». Input1: 3 3 5 0 0 0 1 2 1 0 1 Output1: - Input2: 4 4 5 2 1 0 1 0 0 0 2 1 3 0 0 0 1 7 Output2: 13 This the code I tried to develop: #include //#include //#include //#include #include using namespace std; void findMaxSum(int *a[], int r, int c) { int **res = new int*[r]; for (int i = 0; i < r; i++) { res[i] = new int[c]; for (int j = 0; j < c; j++) res[i][j] = -1; } for (int i = 0; i < r-1; i++) { for (int j = i; j < c-1; j++) { res[i + 1][j + 2] = max(a[i][j] + a[i + 1][j + 2], res[i + 1][j + 2]); res[i + 2][j + 1] = max(a[i][j] + a[i + 2][j + 1], res[i + 2][j + 1]); } } for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) cout << res[i][j] << " "; cout << endl; } delete[] res; /*int result = res[r - 1][c - 1]; if (result == -1) cout << "-"; else cout << result;*/ } int main() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int r, c; cin >> r >> c; int **a = new int*[r]; for (int i = 0; i < r; i++) { a[i] = new int[c]; } for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) cin >> a[i][j]; } findMaxSum(a, r, c); delete[] a; return 0; } Could you help which right for or while loop to use to calculate such sum?
 Re: Knight move, right direction, dynamic programming to get the maximum cost path from top left to right bottom. Richard MacCutchan26-Dec-19 4:25 Richard MacCutchan 26-Dec-19 4:25
 IRichEditOle::InsertObject shifts text one byte ForNow21-Dec-19 18:18 ForNow 21-Dec-19 18:18
 Re: IRichEditOle::InsertObject shifts text one byte Richard MacCutchan21-Dec-19 22:07 Richard MacCutchan 21-Dec-19 22:07
 Re: IRichEditOle::InsertObject shifts text one byte ForNow22-Dec-19 5:09 ForNow 22-Dec-19 5:09
 Re: IRichEditOle::InsertObject shifts text one byte Richard MacCutchan22-Dec-19 22:20 Richard MacCutchan 22-Dec-19 22:20
 Re: IRichEditOle::InsertObject shifts text one byte ForNow23-Dec-19 1:04 ForNow 23-Dec-19 1:04
 Re: IRichEditOle::InsertObject shifts text one byte Richard MacCutchan23-Dec-19 2:03 Richard MacCutchan 23-Dec-19 2:03
 CASE SOLVED AND CLOSED cout and cerr execute out of coded sequence Vaclav_21-Dec-19 10:13 Vaclav_ 21-Dec-19 10:13
 Re: SOLVED cout and cerr execute out of coded sequence Richard MacCutchan21-Dec-19 21:32 Richard MacCutchan 21-Dec-19 21:32
 Re: CASE SOLVED AND CLOSED cout and cerr execute out of coded sequence Richard MacCutchan22-Dec-19 22:55 Richard MacCutchan 22-Dec-19 22:55
 SOLVED CASE CLOSED cout in color and perror - revisited Vaclav_20-Dec-19 4:46 Vaclav_ 20-Dec-19 4:46
 Re: cout in color and perror - revisited leon de boer20-Dec-19 5:01 leon de boer 20-Dec-19 5:01
 Re: cout in color and perror - revisited Vaclav_20-Dec-19 5:48 Vaclav_ 20-Dec-19 5:48
 Re: cout in color and perror - revisited Richard MacCutchan20-Dec-19 6:07 Richard MacCutchan 20-Dec-19 6:07
 Re: cout in color and perror - revisited Vaclav_21-Dec-19 3:10 Vaclav_ 21-Dec-19 3:10
 Re: cout in color and perror - revisited Richard MacCutchan21-Dec-19 3:34 Richard MacCutchan 21-Dec-19 3:34
 Re: cout in color and perror - revisited Vaclav_21-Dec-19 9:05 Vaclav_ 21-Dec-19 9:05
 Last Visit: 31-Dec-99 18:00     Last Update: 25-Jun-24 10:01 Refresh ᐊ Prev1...181182183184185186187188189190 Next ᐅ