Răspuns :
Răspuns:
Explica#include <stdio.h>
#include <stdlib.h>
#define NMAX 500
#define GMAX 250000
#define MOD 999979
int v[NMAX + 1];
int pret[GMAX + 1];
int main() {
FILE *fin = fopen( "rucsac.in", "r" ), *fout = fopen( "rucsac.out", "w" );
int n, i, G, j;
fscanf( fin, "%d%d", &n, &G );
for ( i = 1; i <= n; i ++ ) {
fscanf( fin, "%d", &v[i] );
}
pret[0] = 1;
for ( i = 1; i <= n; i ++ ) {
for ( j = G; j >= v[i]; j -- ) {
pret[j] += pret[j - v[i]];
if ( pret[j] >= MOD )
pret[j] -= MOD;
}
}
fprintf( fout, "%d", pret[G] );
fclose( fin );
fclose( fout );
return 0;
}ție:
Răspuns:
Hopaaa
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int main()
{
int N,K,v[501],nr=0;
f>>N>>K;
for(int i=1;i<=N;i++)
f>>v[i];
for(int i=1;i<=N;i++)
{
int s=v[i];
if(s==K)
nr++;
else
for(int j=i+1;j<=N;j++)
{
s+=v[j];
if(s==K)
{
nr++;
break;
}
if(s>K)
break;
}
}
g<<nr%99979;
return 0;
}
Explicație:
A mea e mai buna;)