/* Borse (selezioni nazionali 2002) Copyright (C) 2002 Paolo Boldi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include FILE *r, *w; int N, ass[50]; /* Assume che siano gią state assegnate borse ai primi nass studenti (e che siano contenute in ass[0], ..., ass[nass-1]). Ora deve assegnare daass migliaia di euro agli studenti rimanenti, senza dare a nessuno pił di max migliaia di euro. Se daass=0, stampa la soluzione corrente. */ void assegna( int daass, int max, int nass ) { int i; if ( daass < 0 ) return; if ( daass ) { for ( i = 1; i <= max; i++ ) { ass[nass] = i; assegna( daass-i, i, nass+1 ); } } else { for ( i = 0; i < nass; i++ ) fprintf( w, "%d ", ass[i] ); fprintf( w, "\n" ); } } int main() { r = fopen( "input.txt", "r" ); w = fopen( "output.txt", "w" ); fscanf( r, "%d", &N ); assegna( N, N, 0 ); fclose( w ); fclose( r ); return 0; }