Cod sursa(job #437006)

Utilizator Bogdan.CirsteaCirstea Bogdan-Ionut Bogdan.Cirstea Data 9 aprilie 2010 03:46:42
Problema Gutui Scor 10
Compilator cpp Status done
Runda teme_upb Marime 2.04 kb
/*


*/

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;


#include <stdio.h>
#include <string.h>
#include <stdlib.h> 


typedef struct gutui_aux
{
int inaltime;
int valoare;
    gutui_aux(int v, double i) {
        valoare = v; inaltime = i;
    };

 gutui_aux(){}
	
 bool operator <(const gutui_aux& gutuie2) const{
        if (inaltime > gutuie2.inaltime ) return true;
        else return false;
    };
}
structuraGutui;

int comparator(const void* gutuie1, const void* gutuie2)
{
	return (*(structuraGutui*)gutuie2).inaltime - (*(structuraGutui*)gutuie1).inaltime;
}

int max(int a, int b)
{
	if (a > b) return a;
	else return b;
}


//PARE OK
//E VREO SITUATIE IN CARE SA NU AJUNGA LA CONDITIA DE OPRIRE?????
//DACA VECTORUL NU E SORTAT NU MAI DA BINE
int profit(structuraGutui* gutui, int i, int n, int inaltime, int pas)
{
	//?????????????
	if ((inaltime <= 0) || (i >= n))
		return 0;	

	if (gutui[i].inaltime <= inaltime)
		return max( (profit(gutui, i+1, n, inaltime - pas, pas) + gutui[i].valoare),
			    profit(gutui, i+1, n, inaltime, pas) );
	

	//AICI E PRACTIC PARTEA CIUDATA PENTRU CA SE INTOARCE IN RECURSIVITATE;
	//DAR E PRACTIC LA FEL CA LA MAX
	//PARE OK TOTUSI
	else	return //max(profit(gutui, i+1, n, inaltime - pas, pas),
			 profit(gutui, i+1, n, inaltime, pas) ;

}


int main()
{
	FILE* fd1;
	FILE* fd2;
	
	fd1=fopen("gutui.out", "w");
	fd2=fopen("gutui.in", "r");

	int numarGutui, height, step;
	fscanf(fd2, "%i %i %i", &numarGutui, &height, &step);
	//printf("Gutui: %i; Inaltime: %i; Step: %i \n", numarGutui, height, step);

	//SAU STRUCTURA - > MAI NATURAL
	structuraGutui gutui[numarGutui]; 
	int i;
	for (i = 0; i < numarGutui; i++)
		fscanf(fd2, "%i %i ", &(gutui[i].inaltime), &(gutui[i].valoare));
	
	sort(gutui, gutui + numarGutui);
		
	for (i = 0; i < numarGutui; i++)
		printf( "%i %i \n", gutui[i].inaltime, gutui[i].valoare);

	//printf("Profit: %i \n", profit(gutui, 0, numarGutui, height, step));
	fprintf(fd1, "%i ", profit(gutui, 0, numarGutui, height, step));

	fclose(fd2);	
	fclose(fd1);
	
	return 0;
	
}