How many HDU 1799 cycles ?, Hdu1799 Loop

Source: Internet
Author: User

How many HDU 1799 cycles ?, Hdu1799 Loop

/*
Question:
Chinese Translation:
Calculate the number of cycles.
Solution:
Difficulties: drawing a table will find it a bit like Yang Hui's triangle, so there is hope to write it down. However, m and n are different in the output, so that the correct result can be output only when the rule is found during debugging.
Key Point: Draw a table, discover the rule from it, and then answer this question.
Problem solving person: lingnichong
Solution time:
Experience in solving the problem: I did not write it at the time. Later, the President gave me some ideas and wrote them based on these ideas. Or that purpose. If you cannot understand the subject, you can write it. If you write it right, you can. You don't care what method you are. In addition, you must have confidence and patience when doing questions.
*/


How many cycles? Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission (s): 2840 Accepted Submission (s): 1029

Problem Description we know that in programming, we often need to consider the time complexity, especially for the loop part. For example,
If
For (I = 1; I <= n; I ++) OP;
N OP operations are performed.
Fori = 1; I <= n; I ++)
For (j = I + 1; j <= n; j ++) OP;
Then, n * (n-1)/2 OP operations are performed.
Now we know that there are m-layer for loop operations, and the starting value of each for variable is the starting value of the previous variable + 1 (the starting value of the first variable is 1 ), the end value is an input n, and the total calculation amount of the OP is asked.
 
Input has T group case, T <= 10000. Each case has two integers, m and n, 0 <m <= 2000, 0 <n <=.
Output outputs a value for each case, indicating the total calculation amount. Maybe this number is large, you only need to Output the remainder except 1007.
Sample Input
21 32 3
 
Sample Output
33
 

#include<stdio.h>#define MAXN 2000+10int a[MAXN][MAXN]={0};int main(){int T,i,j;for(i=0;i<MAXN;i++){a[i][i]=1;a[i][1]=i%1007;}for(i=2;i<MAXN;i++)for(j=1;j<i;j++)a[i][j]=(a[i-1][j-1]+a[i-1][j])%1007;scanf("%d",&T);while(T--){int m,n;scanf("%d%d",&m,&n);printf("%d\n",a[n+1][m+1]);}return 0;}


Code for drawing a table at the beginning

#include<stdio.h> int main(){int i,j,k,l,n;while(~scanf("%d",&n)){int s=0;for(i=1;i<=n;i++)for(j=i+1;j<=n;j++)for(k=j+1;k<=n;k++)for(l=k+1;l<=n;l++)s++;printf("--------------%d-----\n",s);}return 0;}





Hdu 1407 is an amazing question. No matter how hard I create a table or use brute force enumeration, I still feel depressed. I think the same is true of AC. http: // acm

// Direct violence. 280 + MS --
# Include <stdio. h>
Void main ()
{
Int n, I, j, k;
While (scanf ("% d", & n )! = EOF)
{
For (I = 1; I <100; I ++)
{
For (j = 1; j <100; j ++)
{
For (k = 1; k <100; k ++)
{
If (I * I + j * j + k * k = n)
{
Printf ("% d \ n", I, j, k );
Break;
}
}
If (I * I + j * j + k * k = n)
Break;
}
If (I * I + j * j + k * k = n)
Break;
}
}
}

Hdu1671: use the dictionary tree to write the statements that need to release the memory, but have never been written to release the memory (using the C language). Which of the following statements? Take a look. It's easy.

Void release (struct dic * now)
{
If (now = NULL) // It is a good habit to return if it is NULL.

{
Return;

}

Int I;
For (I = 0; I <10; I ++)
{
If (now-> child [I])
{

Release (now-> child [I]);
Now-> child [I] = NULL; // after the memory is released, the pointer value is NULL to prevent the wild pointer.

}

}

Free (now); // release now after the for Loop

}

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.