forked from jainaman224/Algo_Ds_Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamic_Programming_Rod_Cutting.cs
More file actions
42 lines (37 loc) · 952 Bytes
/
Dynamic_Programming_Rod_Cutting.cs
File metadata and controls
42 lines (37 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dynamic_Programming_Rod_Cutting
{
class Program
{
private static int max(int a, int b )
{
return (a > b) ? a : b;
}
private static int money(int[] arr, int size)
{
if(size <= 0)
return 0;
else
{
int max_val = Int32.MinValue;
for (int i = 0; i < size; i++)
max_val = max(max_val, arr[i] + money(arr, size - i - 1));
return max_val;
}
}
static void Main(string[] args)
{
int[] arr = {3, 5, 8, 9, 10, 17, 17, 20};
int size = arr.Length;
Console.Write("Maximum Cost : " + money(arr, size));
Console.Read();
}
}
}
/* OUTPUT
Maximum value is 24
*/