-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.c
71 lines (63 loc) · 1.11 KB
/
10.c
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<stdio.h>
#include<stdlib.h>
int w[10],s[10],f[10],m[10],p[10],i,j,n,c,k=1;
void find(int i);
int max(int a,int b)
{
return (a>b)? a:b;
}
void main()
{
printf("enter the number of requests : \n");
scanf("%d",&n);
printf("enter the start , finish and profit : \n");
for(i=1;i<=n;i++)
{
scanf("%d%d%d",&s[i],&f[i],&w[i]);
}
p[k++]=0;
for(i=2;i<=n;i++)
{
c=0;
for(j=1;j<i;j++)
{
if(s[i]>=f[j])
{
c++;
}
}
p[k++]=c;
}
for(i=1;i<=n;i++)
{
printf("%d\t",p[i]);
}
printf("\n");
m[0]=0;
for(i=1;i<=n;i++)
{
m[i]=max(w[i]+m[p[i]],m[i-1]);
}
for(i=0;i<=n;i++)
{
printf("%d\t",m[i]);
}
printf("\n");
printf("the intervals with max weight is : \n");
find(i);
}
void find(int i)
{
if(i>0)
{
if(w[i]+m[p[i]]>m[i-1])
{
printf("%d - %d : %d\n",s[i],f[i],w[i]);
find(p[i]);
}
else
{
find(i-1);
}
}
}