Description
Input
Output
Sample Input
Sample Output
1 #include<stdio.h> 2 #include<math.h> 3 const int MAXN=100010; 4 int main(){ 5 __int64 N,ans; 6 int T; 7 scanf("%d",&T); 8 while(T--){ 9 ans=0; 10 scanf("%I64d",&N); 11 N++; 12 int flot=0; 13 for(int i=2;i<=sqrt(N);i++)if(N%i==0)ans++; 14 printf("%I64d\n",ans); 15 } 16 return 0; 17 }
Description
Input
Output
Sample Input
Sample Output
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<vector> 4 #include<algorithm> 5 using namespace std; 6 const int MAXN=30010; 7 vector<int>vec; 8 int main(){ 9 int N,x; 10 while(~scanf("%d",&N)){ 11 int top=0; 12 vec.clear(); 13 for(int i=0;i<N;i++){ 14 scanf("%d",&x); 15 if(lower_bound(vec.begin(),vec.end(),x)==vec.end())vec.push_back(x); 16 else *lower_bound(vec.begin(),vec.end(),x)=x; 17 } 18 printf("%d\n",vec.size()); 19 } 20 return 0; 21 }
Description
Input
Output
Sample Input
Sample Output
1 #include<stdio.h> 2 #include<string.h> 3 int main(){ 4 int N,a[150],b[150]; 5 while(~scanf("%d",&N)){ 6 for(int i=0;i<=N;i++)a[i]=1,b[i]=0; 7 for(int i=2;i<=N;i++){ 8 for(int j=0;j<=N;j++){ 9 b[j]+=a[j]; 10 for(int k=i;j+k<=N;k+=i){ 11 b[j+k]+=a[j]; 12 } 13 } 14 for(int j=0;j<=N;j++) 15 a[j]=b[j],b[j]=0; 16 } 17 printf("%d\n",a[N]); 18 } 19 return 0; 20 }
Description
Bessie has gone to the mall‘s jewelry store and spies a charm bracelet. Of course, she‘d like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the supplied list has a weight Wi (1 ≤ Wi ≤ 400), a ‘desirability‘ factor Di (1 ≤ Di ≤ 100), and can be used at most once. Bessie can only support a charm bracelet whose weight is no more than M (1 ≤ M ≤ 12,880).
Given that weight limit as a constraint and a list of the charms with their weights and desirability rating, deduce the maximum possible sum of ratings.
Input
* Line 1: Two space-separated integers: N and M
* Lines 2..N+1: Line i+1 describes charm i with two space-separated integers: Wi and Di
Output
* Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints
Sample Input
4 6 1 4 2 6 3 12 2 7
Sample Output
23
代码:
1 #include<stdio.h> 2 #include<string.h> 3 const int MAXN=200000; 4 int bag[MAXN]; 5 #define MAX(x,y)(x>y?x:y) 6 struct Node{ 7 int w,v; 8 }; 9 Node dt[5000]; 10 int main(){ 11 int N,M; 12 while(~scanf("%d%d",&N,&M)){ 13 memset(bag,0,sizeof(bag)); 14 for(int i=0;i<N;i++)scanf("%d%d",&dt[i].w,&dt[i].v); 15 for(int i=0;i<N;i++){ 16 for(int j=M;j>=dt[i].w;j--){ 17 bag[j]=MAX(bag[j],bag[j-dt[i].w]+dt[i].v); 18 } 19 } 20 printf("%d\n",bag[M]); 21 } 22 return 0; 23 }
原文:http://www.cnblogs.com/handsomecui/p/4841362.html