Jump to content

skate4

Members
  • Posts

    2
  • Joined

  • Last visited

About skate4

  • Birthday 04/03/1991

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

skate4's Achievements

Newbie

Newbie (1/14)

10

Reputation

  1. skate4

    Salut

    Buna tuturor , ma numesc Paul , am 21 de ani , stiu ceva programare si am venit aici ca sa invat mai multe concepte , respectiv sa ajung sa stapensc in timp limbajul c++ , poate si java.
  2. skate4

    Problema C.

    #include <stdio.h> #include <conio.h> int n,x[100],v[100],m=0; int prim(int n){ int i; if(n==0 || n==1) return 0; else if(n==2 || n==3) return 1; else if(n%2==0) return 0; for(i=3;i*i<=n;i+=2) if(n%i==0) return 0; return 1; } void afis(int n){ int i; for(i=1;i<=n;i++) printf("%d ",x[i]); putchar('\n'); } void back(int k,int sp){ int i; for(i=1;i<=m;i++){ x[k]=v[i]; sp=sp+x[k]; if(sp<=n && x[k]>x[k-1]) if(sp==n) afis(k); else back(k+1,sp); sp=sp-x[k]; } } main(){ int i; puts("\nDati n: "); scanf("%d",&n); for(i=2;i<=n;i++) if(prim(i)) { m++; v[m]=i; } back(1,0); getch(); } cam asta ar fi .. trebuie sa stapanesti conceptul de backtracking prima data , si abia apoi poti jongla cu asa ceva.
×
×
  • Create New...