Zoj 2822 Sum of Different Primes (01 backpack)

Source: Internet
Author: User

Zoj 2822 Sum of Different Primes (01 backpack)

/// Calculate the sum of the different k prime numbers that can be divided into n. // 01 backpack, and list the prime numbers # include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
Using namespace std; int cot; int used [1500]; int prime [1500]; void sushu () // prime number table {memset (used, 0, sizeof (used); cot = 0; for (int I = 2; I <= 1120; I ++) {if (! Used [I]) {prime [cot ++] = I; for (int j = 2 * I; j <= 1120; j + = I) used [j] = 1 ;}}int main () {int n, k, I, j, p; int dp [1500] [20]; while (~ Scanf ("% d", & n, & k), n + k) {sushu (); memset (dp, 0, sizeof (dp )); /// 01 backpack dp [0] [0] = 1; for (I = 0; I
     
      
= 1; j --) {for (p = n; p> = prime [I]; p --) dp [p] [j] + = dp [p-prime [I] [J-1];} printf ("% d \ n ", dp [n] [k]);} return 0 ;}
     
    
   
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.